0
我在頁面中嵌入了一個iframe。爲什麼我們需要從iframe中設置perent位置Href,有什麼理由呢?設置父母位置的目的是什麼?
self.parent.location.href = blah blah blah;
我在頁面中嵌入了一個iframe。爲什麼我們需要從iframe中設置perent位置Href,有什麼理由呢?設置父母位置的目的是什麼?
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>
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>
可你更詳細的解釋方式,我是新來這個領域? – user496949