標籤:js ifram top.location.href和localtion.href
top.location.href=”url” 在頂層頁面開啟url(跳出架構)
self.location.href=”url” 僅在本頁面開啟url地址
parent.location.href=”url” 在父視窗開啟Url地址
this.location.href=”url” 用法和self的用法一致
if (top.location == self.location) 判斷當前location 是否為頂層來 禁止frame引用
如果頁面當中有自訂的frame的話,也可以將parent self top換為自訂frame的名稱效果就是在自訂frame視窗開啟url地址
實際中可能這樣使用
if(top !== self){
top.location.href = location.href;
} 禁止frame引用
以下是從網上找到的一個例子,不是很直觀, 我加了上面那三行代碼, 可以先去掉, 再加上, 看一下效果,就很清楚了 以下是top.htm 代碼
<script language=javascript> function rs(){
if(top !== self){
top.location.href = location.href;
}
parent.left.location.href="top.htm"
parent.bot.location.href="top.htm"
}
< /script>
input type=button name=name value="ksdj" onclick=rs();>
以下是一個隨意檔案名稱的htm檔案: <FRAMESET COLS="150,*"> < FRAME SRC="left.htm" name=left> < FRAMESET ROWS="150,*"> < FRAME SRC="top.htm" name=top> < FRAME SRC="bot.htm" name=bot> < /FRAMESET> < /FRAMESET> 你自己試試,我想你要的可能就是這樣的效果!
top表示主視窗,location表示當前視窗,如果你的檔案只有一個架構,沒有iframe和frmaeset,那麼是完全一致的,沒有區別。
top.location是在頂層frame中開啟新頁 window.location是在當前frame中開啟新頁
parent.location 在當前視窗的父視窗開啟Url地址
top表示主視窗,location表示當前視窗,如果你的檔案只有一個架構,沒有iframe和frmaeset,那麼是完全一致的,沒有區別。
top.location.href和localtion.href有什麼不同