我有这个脚本:
<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;
控制台在那一行告诉我:
未捕获的类型错误:无法读取未定义的属性“正文”
我该怎么做才能让它在 Chrome 上运行?