码迷,mamicode.com
首页 > Web开发 > 详细

关于js的地址跳转

时间:2018-02-09 22:37:45      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:too   err   iframe   baidu   防止   htm   idt   menu   reload   

一、基本的地址跳转

解说:

window.open 弹出新窗口的命令;     page.html‘ 弹出窗口的文件名;    ‘newwindow‘ 弹出窗口的名字(不是文件名),非必须,可用空‘代替; height=100 窗口高度;  width=500 窗口宽度;  top=0 窗口距离屏幕上方的象素值;  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 指代当前窗口对象,属于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";
}

  

 

关于js的地址跳转

标签:too   err   iframe   baidu   防止   htm   idt   menu   reload   

原文地址:https://www.cnblogs.com/qqing/p/8436717.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!