Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome Javascript and frames not working

I have reproduced this problem with chrome (with firefox and with IE works fine). I have two files, one is test_index.html and other is test.html.

the code of test_index is the following:

<html>
<head>


<meta name=description content="">
<meta name=keywords content="">
<Title></Title>
</head>

<frameset cols="190,*" framespacing="0" border="0" frameborder="0">
<frame name="menu_frame" target="principale" src="test.html" marginwidth="0" marginheight="0" scrolling="auto">
<frame name="principale" src="" scrolling="no" marginwidth="0" marginheight="0" target="principale">
</frameset>

</html>

the code of test.html is the following:

<html>
<head>
<script type="text/javascript">
function writedoc() {
    newWindow = window.open( '','principale','width=100%');
    newWindow.document.open();
    newWindow.document.writeln('<html><head><title>Pictures Slide Show</title></head><body><p>Hello World</p></body></html>');
}
</script>
</head>
<body>

<input type="button" onclick="writedoc()"  />

</body>
</html>

So when I click the button nothing happens in chrome, what am i doing wrong?

like image 369
user1238784 Avatar asked Jan 25 '26 05:01

user1238784


1 Answers

In Chrome (i)frames are treated as cross-domain windows when running local pages (i.e. with file protocol). (Why?). Passing --allow-file-access-from-files switch at start-up should tackle the problem (credits @Justin).

Some observations of your code

  • framesets and frames are obsoleted in HTML5, if you really need external windows, use iframes instead.
  • Attribute values should be always wrapped in quotes. Unwrapped attributes are working now, but they might not work in the future. Also values containing spaces will break the markup.
  • A simple reference to (i)frame's window object is window.frames['frame_name'], you don't need complex window.open()
  • document.open() is not needed, document.write(ln)() opens the document automatically
  • After document.write(ln)() you have to close the document with document.close() to stop browser loading
like image 84
Teemu Avatar answered Jan 26 '26 18:01

Teemu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!