gpt4 book ai didi

javascript - Chrome Javascript 和框架无法正常工作

转载 作者:行者123 更新时间:2023-11-28 03:23:20 25 4
gpt4 key购买 nike

我已经用 chrome 重现了这个问题(用 firefox 和 IE 工作正常)。我有两个文件,一个是 test_index.html,另一个是 test.html。

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>

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>

所以当我点击按钮时,chrome 没有任何反应,我做错了什么?

最佳答案

在 Chrome 中,(i)frames 在运行本地页面时被视为跨域窗口(即使用文件协议(protocol))。 (Why?)。在启动时传递 --allow-file-access-from-files 开关应该可以解决问题 ( credits @Justin )。

对您的代码的一些观察

  • framesetframe 在 HTML5 中已经过时,如果您确实需要外部窗口,请改用 iframe
  • 属性值应始终用引号引起来。展开的属性现在可以使用,但将来可能无法使用。包含空格的值也会破坏标记。
  • (i)framewindow 对象的简单引用是 window.frames['frame_name'],你不需要需要复杂的 window.open()
  • 不需要
  • document.open()document.write(ln)()自动打开文档
  • document.write(ln)() 之后,您必须使用 document.close() 关闭文档以停止浏览器加载

关于javascript - Chrome Javascript 和框架无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22842749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com