Javascript 什么';设置父位置的目的是什么?
我在页面中嵌入了一个iframe。为什么我们需要从iframe设置perent location Href,有什么原因吗Javascript 什么';设置父位置的目的是什么?,javascript,html,Javascript,Html,我在页面中嵌入了一个iframe。为什么我们需要从iframe设置perent location Href,有什么原因吗 self.parent.location.href = blah blah blah; 这通常是一种断帧技术 通常是这样的: if(self != top)top.location.href=someUrl; 由于可以在页面正文中放置iframe标记,因此可以使用top操作主窗口。见: 主页 <!--This is the main page--> <h
self.parent.location.href = blah blah blah;
这通常是一种断帧技术 通常是这样的:
if(self != top)top.location.href=someUrl;
由于可以在页面正文中放置iframe标记,因此可以使用
top
操作主窗口。见:
主页
<!--This is the main page-->
<html>
<head>
<script>
alert(window.top.location.href);//The main page's URL
alert(window.self.location.href);//The main page's URL
alert(window.top.location.href);//The main page's URL
</script>
</head>
<body>
<iframe src="myFrame.html"></iframe>
</body>
</html>
警报(window.top.location.href)//主页的URL
警报(window.self.location.href)//主页的URL
警报(window.top.location.href)//主页的URL
myFrame.html
<html>
<head>
<script>
alert(window.location.href);//"myFrame.html"
alert(window.self.location.href);//"myFrame.html"
alert(window.top.location.href);//The main page's URL
</script>
</head>
<body>
</body>
</html>
警报(window.location.href)//“myFrame.html”
警报(window.self.location.href)//“myFrame.html”
警报(window.top.location.href)//主页的URL
你能更详细地解释一下吗,我是这方面的新手?