2014-04-03 31 views
2

我已经转载了这个问题与铬(与Firefox和IE工作正常)。 我有两个文件,一个是test_index.html,另一个是test.html。铬Javascript和框架无法正常工作

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

所以,当我按一下按钮没有任何反应在铬,我是什么?做错了?

+1

嗨,只是柜面你不知道帧在HTML不赞成现在:http://stackoverflow.com/questions/4263509/why-are-frames-deprecated-in-html –

+0

这是一个很lo因为我们不推荐使用框架,因为我们不推荐使用这些框架,但我认为您不需要这样做'window.open'来引用'principale'框架 –

+1

如果您在本地运行这个框架,Chrome阻止帧,因为它们是跨域的。这应该在服务器上工作,但。但你真的应该将属性值包裹在引号中... – Teemu

回答

0

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

代码

  • frameset S和frame S的一些意见已过时的HTML5,如果你真的需要外窗,使用iframe!而非。
  • 属性值应该始终用引号括起来。未包装的属性现在正在工作,但他们未来可能无法使用。包含空格的值也会打破标记。
  • 一个简单的参考(i)framewindow对象是window.frames['frame_name'],你不需要复杂的window.open()
  • document.open()是不需要的,document.write(ln)()打开文档自动
  • document.write(ln)()后,必须与document.close()关闭文档停止浏览器加载
0

它曾与我对铬当我点击该按钮它拿给我一个窗口的“Hello world”,

尝试添加“”中的cols:的cols =“190,*”

+0

我尝试添加,但仍然无法正常工作,什么版本的铬? – user1238784

+0

其他人可以用chrome来试试吗?对我而言,只适用于IE和Firefox – user1238784