getElementsByTagName不起作用

我正在使用NODE JS模块,我正在创build一个HTTP服务器。 服务器的响应是一个包含JavaScript的页面,该页面将网页embedded到<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> 

我在这里得到的错误为“对象[对象的全局]没有方法'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. 

第一个错误是由这一行引起的:

 window.history.pushstate(0,0,c); 

正确的代码是:

 window.history.pushState(0,0,c); 

注意大写字母S

至于另一个错误,当在本地查看文件时,您不能访问iframe和其他“受限制”的function,如AJAX。 您必须将其上载到服务器(或在本地计算机上启动服务器)才能使用这些function。