Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在Firefox上是否有一种允许脚本但阻止顶部导航的方法?_Javascript_Html_Google Chrome_Firefox - Fatal编程技术网

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将
允许脚本
,而不允许
顶部导航