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; http://www.b.com!=http://www.a.com,返回為真(true),則網頁重定向到你的網頁,做到防盜用的作用.
參考鏈接:https://www.cnblogs.com/THONLY/p/7246127.html