考虑以下三页。
Foo.html
在浏览器中本地打开,因此有一个带有前缀的 URLfile:///
。Bar.html
是在同一个目录下Foo.html
。Bar2.html
住在里面,/var/www
我正在Apache
继续localhost
。
Foo.html
<html>
<head>
<script>
foo = function() {
alert("frame changed");
};
</script>
</head>
<body>
<iframe width="200" height="300" src="Bar.html" id="my-iframe" onLoad="foo" />
</body>
</html>
酒吧.html
<html>
<body>
<iframe width="200" height="300" src="http://localhost/Bar2.html" id="my-iframe" />
</body>
</html>
Bar2.html
<html>
<head>
<script>
if (top.location != self.location){
parent.location = self.location;
}
</script>
</head>
<body>
<button type="button" onclick="document.location.href='http://bing.com'">Hello World</button>
</body>
</html>
当Foo.html
在 Firefox 中加载时,通过firefox /path/to/Foo.html
在命令行上运行,框架破坏代码中Bar2.html
的Bar.html
. 此时,用户会收到警报frame changed
。
当我单击按钮时,iframe
更改(按钮消失),但我没有收到警报。
为什么onLoad
页面更改时第二次不触发?