0

I have been trying to run a javascript code over an iframe in an index.php file but not getting any success so if you people can please have a look at this that what I am doing wrong please:

Here is my code as :

<script type="text/javascript">
window.onload = function() {
document.getElementById("resultFrame").contentWindow.iframe();
function iframe() {
var isCandidateRegion=function(node){
return (node.innerText.indexOf('Username')>-1 && node.innerText.indexOf('Hours')>-1);
};
//Find the last table in th document that contains 'Username' and 'Hours'
var candidateRegions=[].filter.call(document.querySelectorAll('table'),isCandidateRegion);
var targetRegion=candidateRegions[candidateRegions.length-1];
var isVisible=function(node){
return (node.offsetWidth && node.offSetWidth >0) || (node.offsetHeight && node.offsetHeight>0);
};
var inputs=[].filter.call(targetRegion.querySelectorAll('input'),isVisible);
inputs[0].value="nicefellow1234";
inputs[1].value="23";
inputs[2].click();
};
};
</script>

<iframe id="resultFrame" src="http://www.infamousgangsters.com/site.php?page=kill" height="700px" width="100%"></iframe>

Also I am getting an error in console as follows :

Error: Permission denied to access property 'iframe'

so if you people can help me please..!

2
  • 3
    Read up on Same-Origin Policy and CORS. Commented Jan 2, 2015 at 20:48
  • 1
    At-least read the Same-Origin Policy article. It describes your problem, and documents the way the iframe can grant you access, and why the iframe must grant you access to protect user security. Commented Jan 2, 2015 at 20:56

1 Answer 1

1

I believe it is being denied because the domain is different to the one the iframe is hosted in. This is to protect users from XSS attacks.

Sign up to request clarification or add additional context in comments.

3 Comments

so what can be the solution then?
There is none. You can't mess with documents from other origins.
You can post between frames across domains using form submissions. That's about it though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.