js 跳轉鏈接的幾種方式
阿新 • • 發佈:2018-11-10
上一頁 ring 默認 syn href his 外部 div ref
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
js 跳轉鏈接的幾種方式