关于js的地址跳转

一、基本的地址跳转

解说:

window.open 弹出新窗口的命令;     page.html' 弹出窗口的文件名;    'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空'代替; height=100 窗口高度;  left=0 窗口距离屏幕左侧的象素值。

window.location.href = "页面地址"; //当前页跳转  相当于 <a href="baidu.com" target="_self">go baidu</a>  
window.open('页面地址'); //打开新页面   相当于<a href="baidu.com" target="_blank">go baidu</a>
window.open('page.html', 'newwindow', 'height=100, width=400, top=0,left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no')

 

二、返回上一页,当页刷新

window.history.back(-1); //返回上一页
window.history.back(); //返回上一页
document.referrer;  //返回上一页,也用于获取上一页的链接,假如没有上一页则返回"",多用于移动端

location.reload(); //当页刷新
window.location.go(-1); //返回上一页并刷新
self.location=document.referrer; //返回上一页并刷新

  

三、其他的页面跳转

解说:

 self 指代当前窗口对象,属于window 最上层的对象。

location.href 指的是某window对象的url的地址

 self.location.href 指当前窗口的url地址,去掉self默认为当前窗口的url地址,一般用于防止外部的引用

top.location.href:为引用test.html页面url的父窗口对象的url

top指代的是主体窗口

self.location.href = "baidu.com" 
top.location.href = '页面地址';

//假如要页面a跳出iframe框架
if(top.location.href != self.location.href) {
	location.href = "页面a";
}