JavaScript Chrome 问题
我有这个脚本:
<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>
此代码打开一个文件(现在是 lineData.txt)并将其放在文本区域中。此代码适用于 Firefox 和 IE,但不适用于 Chrome。
问题出在
window.frames.messageTxt.document.body.lastChild.lastChild.data;
控制台上,在该行中告诉我:
未捕获类型错误:无法读取未定义的属性“body”
我该如何使其在 Chrome 上工作?
I've this script:
<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>
This code open a file (now lineData.txt) and put it on a textarea. This code works on Firefox and IE but doesn't work on Chrome.
The problem is on
window.frames.messageTxt.document.body.lastChild.lastChild.data;
The console tell me in that line:
Uncaught TypeError: Cannot read property 'body' of undefined
How can I do to make it works on Chrome ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在本地进行测试(例如 file://C:/.../test.html),您将无法在 Chrome 中正确访问框架/iframe。
If you are testing locally (eg file://C:/.../test.html) you won't be able to properly access frames/iframes in Chrome.