Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/438.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript浏览器问题_Javascript_Google Chrome_Typeerror_Uncaught Exception - Fatal编程技术网

JavaScript浏览器问题

JavaScript浏览器问题,javascript,google-chrome,typeerror,uncaught-exception,Javascript,Google Chrome,Typeerror,Uncaught Exception,我有以下脚本: <html> <head> <script type="text/javascript"> function init(){ var extText = window.frames.messageTxt.document.body.lastChild.lastChild.data; extText = extText.replace(/[\r\n]/g," "); document.forms[0].nMessage.value = ext

我有以下脚本:

<html>
<head>
<script type="text/javascript">

function init(){

var extText = window.frames.messageTxt.document.body.lastChild.lastChild.data;
extText = extText.replace(/[\r\n]/g," ");
document.forms[0].nMessage.value = extText;
}

window.onload=init;

</script>
</head>
<body>
<iframe name='messageTxt' src='lineData.txt' style='display:none'></iframe>
<form>
<textarea name='nMessage'></textarea>
</form>
</body>
</html>
控制台在那行告诉我:

未捕获的TypeError:无法读取未定义的属性“body”


如何使其在Chrome上工作?

如果您在本地进行测试(例如文件:/…/test.html),您将无法正确访问Chrome中的帧/iFrame。

它在Chrome12中对我有效。你能设置一个不适合你的示例吗?@Diego Stamigni Chrome不会将所有本地文件视为来自同一个域;相反,它认为它们完全不同。因此,默认安全策略不允许访问。如果您想这样做,可以使用命令行选项“允许从文件访问文件”启动Chrome。在启动带有该标志的新Chrome进程之前,您必须确保完全停止所有Chrome进程。
window.frames.messageTxt.document.body.lastChild.lastChild.data;