js中top.location.href、parent.location.href用法

來源:互聯網
上載者:User

window.location.href、location.href是本頁面跳轉

parent.location.href是上一層頁面跳轉

top.location.href是最外層的頁面跳轉

舉例說明:

window.location.href、location.href:

例:

 代碼如下 複製代碼

window.location.href= 'wapsend1.asp?zimu=A&rev= '   +   form1.rev.value ;

parent.location.href:C頁面跳轉

例:

 代碼如下 複製代碼

window.parent.parent.location.href=“你定義要跳轉的頁面”

top.location.href:A頁面跳轉

例:

在form提交表單的時候有個屬性可能對上面的(2)的情況有用target=_top

 代碼如下 複製代碼

<form name=loginForm action=Login.action method=post target=_top>

</form>

例2

 代碼如下 複製代碼

echo <iframe width=0 height=0 frameborder=0 scrolling=auto src='登入論壇' onload='reurl()'></iframe>;
echo <script> function reurl(){top.location.href='.$url.'}</script>;

也可以直接在表單提交是的target加個即可

<form>: form提交後D頁面跳轉

<form target=_blank>: form提交後彈出新頁面

<form target=_parent>: form提交後C頁面跳轉

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.