Chrome Javascript 和框架不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22842749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Chrome Javascript and frames not working
提问by user1238784
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.
我已经用 chrome 重现了这个问题(用 firefox 和 IE 工作正常)。我有两个文件,一个是 test_index.html,另一个是 test.html。
the code of test_index is the following:
test_index 的代码如下:
<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:
test.html 的代码如下:
<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?
因此,当我单击按钮时,chrome 中没有任何反应,我做错了什么?
采纳答案by Teemu
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).
在 Chrome(i)frames
中运行本地页面(即使用文件协议)时被视为跨域窗口。(为什么?)。--allow-file-access-from-files
在启动时传递switch 应该可以解决这个问题(感谢@Justin)。
Some observations of your code
对您的代码的一些观察
frameset
s andframe
s are obsoleted in HTML5, if you really need external windows, useiframe
s 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
'swindow
object iswindow.frames['frame_name']
, you don't need complexwindow.open()
document.open()
is not needed,document.write(ln)()
opens the document automatically- After
document.write(ln)()
you have to close the document withdocument.close()
to stop browser loading
frameset
s 和frame
s 在 HTML5 中已过时,如果您确实需要外部窗口,请改用iframe
s。- 属性值应始终用引号括起来。未包装的属性现在可以使用,但将来可能无法使用。包含空格的值也会破坏标记。
- 对
(i)frame
'swindow
对象的简单引用是window.frames['frame_name']
,您不需要复杂的window.open()
document.open()
不需要,document.write(ln)()
自动打开文档- 在
document.write(ln)()
您必须关闭文档document.close()
以停止浏览器加载后
回答by Mejri Yassine
It worked with me on chrome when i clicked the button it showed to me a window "Hello world" in it,
当我单击它向我显示一个窗口“Hello world”的按钮时,它在 chrome 上与我一起工作,
try to add "" in cols : cols="190,*"
尝试在 cols 中添加 "": cols="190,*"