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 ?
-
It works for me in Chrome12. Can you set up an example that doesn't work for you?dvir– dvir2011年06月08日 11:02:28 +00:00Commented Jun 8, 2011 at 11:02
1 Answer 1
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
circusbred
1,2408 silver badges8 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Pointy
@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.
Explore related questions
See similar questions with these tags.
lang-js