我一直在尝试在index.php文件中的iframe上运行javascript代码,但没有取得任何成功,所以如果你们可以请看一下我做错了什么:
这是我的代码:
<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>
此外,我在控制台中收到如下错误:
Error: Permission denied to access property 'iframe'
所以如果你们可以帮助我......!
最佳答案
我认为它被拒绝是因为该域与托管 iframe 的域不同。这是为了保护用户免受 XSS 攻击。
关于javascript - 如何在 iframe 上运行 javascript 代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27748329/