關於js中window.location.href,location.href,parent.location.href,top.location.href的用法


"window.location.href"、"location.href"是本頁面跳轉.
"parent.location.href" 是上一層頁面跳轉.
"top.location.href" 是最外層的頁面跳轉.
舉例說明:
    如果A,B,C,D都是html,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js這樣寫
    "window.location.href"、"location.href":D頁面跳轉
    "parent.location.href":C頁面跳轉
    "top.location.href":A頁面跳轉
如果D頁面中有form的話,
    <form>:  form提交后D頁面跳轉
    <form target="_blank">:  form提交后彈出新頁面
    <form target="_parent">:  form提交后C頁面跳轉
    <form target="_top"> :  form提交后A頁面跳轉

如果訪問的是iframe里面的頁面,重新加載最外層的頁面

<html>
<head>
<title></title>
<script language="javascript">
function escapeFrame(){
      
if (window.top.location.href != window.location.href) {
        window.top.location.reload();
      }
}
</script>
</head>

<body onload="escapeFrame()">
<iframe src="b.html" ></iframe>
</body>
</html>

 

原鏈接:http://www.blogjava.net/secret/archive/2011/06/28/353132.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM