开发者

JavaScript Chrome Problem

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 ?


If you are testing locally (eg file://C:/.../test.html) you won't be able to properly access frames/iframes in Chrome.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜