我正在使用创建 HTTP 服务器的 NODE JS 模块。服务器的响应是一个包含 JavaScript 的页面,该页面嵌入了一个网页,<iframe>
我<iframe>
正在访问它的元素数据getElementsByTagName
。
这是响应代码:
<html>
<head>
<script type='text/javascript'>
function test() {
document.body.innerHTML='<iframe id="ifool" src="file:///C:/Users/Naman/Desktop/rew.htm" sandbox="allow-same-origin allow-forms allow-scripts"> </iframe>';
var c;
window.setInterval(function(){
c=document.getElementById("ifool").contentWindow.location.href;
window.history.pushstate(0,0,c);
},100);
window.setInterval(function () {
var x = document.getElementById("ifool");
var y = (x.contentWindow || x.contentDocument);
if (y.document) y = y.document;
try {
var a = y.getElementsByTagName("input")[0].value;
var b = y.getElementsByTagName("input")[1].value;
} catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.message + "\n\n";
txt += "Click OK to continue.\n\n";
alert(txt);
}
}, 2000);
</script>
</head>
<body onload= 'test()'>
</body>
</html>
我在这里收到错误,因为“对象 [object global] 没有方法 'getElementsByTagName'”。我正在使用 Chrome,但我也尝试过 Firefox。
在检查元素控制台中,我还收到以下错误-
Uncaught TypeError: Object #<History> has no method 'pushstate' localhost: Unsafe JavaScript attempt to access frame with URL file:///C:/Users/Naman/Desktop/rew.htm from frame with URL http://localhost:8080/. Domains, protocols and ports must match.