js 跳轉連結的幾種方式
阿新 • • 發佈:2018-11-10
1、跳轉連結 在當前視窗開啟
window.location.href="http://www.baidu.com" 等價於 <a href="baidu.com" target="_self">go baidu</a>
2、跳轉連結 在新視窗開啟
window.open("http://www.baidu.com") 等價於 <a href="baidu.com" target="_blank">go baidu</a>
3、跳轉連結 返回上一頁
window.history.back(-1);
4、跳轉連結
self.location.href="baidu.com"
self 指代當前視窗物件,屬於window 最上層的物件。
location.href 指的是某window物件的url的地址
self.location.href 指當前視窗的url地址,去掉self預設為當前視窗的url地址,一般用於防止外部的引用
top.location.href:為引用test.html頁面url的父視窗物件的url
如果你的網頁地址是:http://www.a.com,別人的是http://www.b.com, 他在他的頁面用iframe等框架引用你的http://www.a.com,那麼你可以用:
if
(top.location.href!=self.location.href){
location.href=
"http://www.a.com"
;
}
來轉向你的頁面,top指代的是主體視窗,這裡top.location.href返回 http://www.b.com
window.location.href="http://www.baidu.com" 等價於 <a href="baidu.com" target="_self">go baidu</a>
2、跳轉連結 在新視窗開啟
window.open("http://www.baidu.com") 等價於 <a href="baidu.com" target="_blank">go baidu</a>
3、跳轉連結 返回上一頁
window.history.back(-1);
4、跳轉連結
self.location.href="baidu.com"
self 指代當前視窗物件,屬於window 最上層的物件。
location.href 指的是某window物件的url的地址
self.location.href 指當前視窗的url地址,去掉self預設為當前視窗的url地址,一般用於防止外部的引用
top.location.href:為引用test.html頁面url的父視窗物件的url
如果你的網頁地址是:http://www.a.com,別人的是http://www.b.com, 他在他的頁面用iframe等框架引用你的http://www.a.com,那麼你可以用:
if
(top.location.href!=self.location.href){
location.href=
"http://www.a.com"
;
}
來轉向你的頁面,top指代的是主體視窗,這裡top.location.href返回http://www.b.com