Javascript 在Firefox上是否有一种允许脚本但阻止顶部导航的方法?
在下面的示例中,Javascript 在Firefox上是否有一种允许脚本但阻止顶部导航的方法?,javascript,html,google-chrome,firefox,Javascript,Html,Google Chrome,Firefox,在下面的示例中,Foo.html位于/tmp/中,在没有web服务器的情况下本地访问,Bar.html位于/var/www/中,由Apache提供服务 此配置导致Foo.html和Bar.html位于不同的来源,但这对于使示例重现性很重要 Foo.html <html> <script> foo = function() { alert("foo says hi"); }; </script> <iframe sandbox="allow-forms a
Foo.html
位于/tmp/
中,在没有web服务器的情况下本地访问,Bar.html
位于/var/www/
中,由Apache提供服务
此配置导致Foo.html
和Bar.html
位于不同的来源,但这对于使示例重现性很重要
Foo.html
<html>
<script>
foo = function() {
alert("foo says hi");
};
</script>
<iframe sandbox="allow-forms allow-scripts" width="200" height="300" src="http://localhost/Bar.html" onLoad="foo();" />
</html>
<html>
<script>
if(top.location != self.location){
parent.location = self.location;
}
</script>
<form action="about:blank" method="post">
<input type="text" name="destination_username" value=""/>
<input type="text" name="quantity" value=""/>
<input type="submit" value="Submit" />
</form>
</html>
foo=函数(){
警惕(“福说你好”);
};
Bar.html
<html>
<script>
foo = function() {
alert("foo says hi");
};
</script>
<iframe sandbox="allow-forms allow-scripts" width="200" height="300" src="http://localhost/Bar.html" onLoad="foo();" />
</html>
<html>
<script>
if(top.location != self.location){
parent.location = self.location;
}
</script>
<form action="about:blank" method="post">
<input type="text" name="destination_username" value=""/>
<input type="text" name="quantity" value=""/>
<input type="submit" value="Submit" />
</form>
</html>
if(top.location!=self.location){
parent.location=self.location;
}
在Firefox(Linux上的V27)中,如果加载了Foo.html
,Bar.html
能够跳出框架(成为顶部框架),尽管沙盒属性中缺少允许顶部导航
在Chrome中,如果加载了Foo.html
,Bar.html
无法跳出框架
看起来,sandbox
在Firefox中的实现不正确。在Firefox中是否有一些HTML属性或JS hack将允许脚本
,而不允许顶部导航