JS實(shí)現(xiàn)頁面跳轉(zhuǎn)鏈接的幾種方式匯總
js實(shí)現(xiàn)頁面跳轉(zhuǎn)鏈接的幾種方式
1、在當(dāng)前窗口打開
window.location. rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" // 等價(jià)于 <a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_self">跳轉(zhuǎn)到百度</a>
2、在新窗口打開
window.open("http://www.baidu.com") // 等價(jià)于 <a rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" target="_blank">跳轉(zhuǎn)到百度</a>
3、返回上一頁
window.history.back(-1)
4、跳轉(zhuǎn)鏈接
self.location. rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow"
self 指代當(dāng)前窗口對象,屬于window 最上層的對象。
location.href // 指的是某window對象的url的地址 self.location.href // 指當(dāng)前窗口的url地址,去掉self默認(rèn)為當(dāng)前窗口的url地址,一般用于防止外部的引用 top.location.href // 為引用test.html頁面url的父窗口對象的url
如果你的網(wǎng)頁地址是:http://www.a.com,別人的是http://www.b.com, 他在他的頁面用iframe等框架引用你的http://www.a.com,那么你可以用:
if(top.location.href!=self.location.href){ location. rel="external nofollow" ; }
來轉(zhuǎn)向你的頁面,top指代的是主體窗口,這里top.location.href返回http://www.b.com;
下面簡單總結(jié)了幾種頁面跳轉(zhuǎn)功能的實(shí)現(xiàn)
第一種:使用JS跳轉(zhuǎn)頁面
1)跳轉(zhuǎn)帶參
<script language="javascript" type="text/javascript"> window.location. rel="external nofollow" + window.location.href; </script>
2)跳轉(zhuǎn)無參
<script>window.location.;</script>
第二種:返回上一次預(yù)覽界面
<script language="javascript"> alert("返回"); window.history.back(-1); </script>
HTML頁面嵌套
<a href="javascript:history.go(-1)" rel="external nofollow" >返回上一步</a> <a href="<%=Request.ServerVariables(" rel="external nofollow" HTTP_REFERER")%>">返回上一步</a>
第三種:button按鈕添加事件跳轉(zhuǎn)
<input name="前端知音" type="button" value="前端知音" onClick="location.href='login.do'">
第四種:在新窗口打開
<a href="javascript:" rel="external nofollow" onClick="window.open('login.do','','height=500,width=611,scrollbars=yes,status=yes')">新窗口</a>
第五種:通過meta設(shè)置跳轉(zhuǎn)頁面
<head> <!--只刷新不跳轉(zhuǎn) --> <meta http-equiv="refresh" content="5"> <!--定時(shí)跳轉(zhuǎn) --> <meta http-equiv="refresh" content="5;url=index.html"> </head>
到此這篇關(guān)于JS實(shí)現(xiàn)頁面跳轉(zhuǎn)鏈接的幾種方式的文章就介紹到這了,更多相關(guān)js頁面跳轉(zhuǎn)鏈接內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
微信小程序 動態(tài)綁定數(shù)據(jù)及動態(tài)事件處理
這篇文章主要介紹了微信小程序 動態(tài)綁定數(shù)據(jù)及動態(tài)事件處理的相關(guān)資料,需要的朋友可以參考下2017-03-03javascript實(shí)現(xiàn)任務(wù)欄消息提示的簡單實(shí)例
下面小編就為大家?guī)硪黄猨avascript實(shí)現(xiàn)任務(wù)欄消息提示的簡單實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05JavaScript正則表達(dá)式中g(shù)標(biāo)志詳解
正則的思想都是一樣的,但是具體的寫法會有所不同,下面這篇文章主要給大家介紹了關(guān)于JavaScript正則表達(dá)式中g(shù)標(biāo)志的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03JavaScript中具名函數(shù)的多種調(diào)用方式總結(jié)
這篇文章主要介紹了JavaScript中具名函數(shù)的多種調(diào)用方式總結(jié),本文總結(jié)了4種方法,需要的朋友可以參考下2014-11-11如何使用JavaScript檢測空閑的瀏覽器選項(xiàng)卡
這篇文章主要介紹了如何使用JavaScript檢測空閑的瀏覽器選項(xiàng)卡,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-05-05純js實(shí)現(xiàn)仿QQ郵箱彈出確認(rèn)框
仿QQ郵箱的彈出層,彈出確認(rèn)框,主要是用火狐的firebug把html和css扣了下來,沒有做封裝,就定義了一個拖動事件. 大家可以封裝自己的彈出窗,嘿嘿!2015-04-04