最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Chrome Javascript and frames not working - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Apr 3, 2014 at 16:08 user1238784 asked Apr 3, 2014 at 15:50 user1238784user1238784 2,4603 gold badges27 silver badges42 bronze badges 6
  • 1 Hi, just incase you don't know frames are deprecated in HTML now: stackoverflow./questions/4263509/… – Billy Moat Commented Apr 3, 2014 at 15:53
  • It's been a very long time since I didn't work with frames since they're deprecated, but I don't think you need to do this window.open to refer to the principale frame – Laurent S. Commented Apr 3, 2014 at 15:54
  • 1 If you're running this locally, Chrome blocks frames as they were cross-domain. This should be working on a server though. But you really should wrap attribute values within quotes... – Teemu Commented Apr 3, 2014 at 16:04
  • Hi yes I am running it locally. Is there any work-around, can I use iframes instead of frames? – user1238784 Commented Apr 3, 2014 at 16:05
  • 1 Please check this SO answer, though I'm not sure if it still works. The same happens with iframes, they are also blocked. Btw. A simple way to write to a frame would be: window.frames['principale'].document.writeln(...);. – Teemu Commented Apr 3, 2014 at 16:07
 |  Show 1 more ment

2 Answers 2

Reset to default 1

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 plex 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

It worked with me on chrome when i clicked the button it showed to me a window "Hello world" in it,

try to add "" in cols : cols="190,*"

发布评论

评论列表(0)

  1. 暂无评论