user4089052
user4089052

Reputation: 43

How to run a javascript code over an iframe?

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..!

Upvotes: 0

Views: 86

Answers (1)

garryp
garryp

Reputation: 5766

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.

Upvotes: 1

Related Questions