2

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 ?

asked Jun 8, 2011 at 10:57
1
  • It works for me in Chrome12. Can you set up an example that doesn't work for you? Commented Jun 8, 2011 at 11:02

1 Answer 1

2

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

answered Jun 8, 2011 at 11:11
Sign up to request clarification or add additional context in comments.

1 Comment

@Diego Stamigni Chrome does not treat all local files as being from the same domain; instead, it thinks they're all distinctly different. Therefore, the default security policy does not allow access. If you want to do that, you can start Chrome with the command-line option "--allow-file-access-from-files". You have to make sure you completely stop all Chrome processes before starting up a new one with that flag.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.