js刷新页面常用方法总结
文章目录
最近在一个大杂烩里面,安插自己的一个项目,用dva 撸的一个发布管理系统,写的我是心力交瘁,焦头烂额~~~然后,接下来是今天的学习,其实也是自己平时没怎么注意到的问题 关于页面刷新常用的手法 history.go(0) history.reload() location = location location.assgin(location) document.execCommand('Refresh') window.nvigate(location) location.replace(location) document.URL = location.href 自动刷新:
<meta http-equiv="refresh" content="20">
// 20 是指每隔 20秒刷新以面自动转跳页面
<meta http-equiv="refresh" content="20;url=http://www.xxx.net">
// 其 中20指隔20秒后跳转到http://www.xxx.net页面
2. js 当前页面的刷新方法
self.location.href // 当前页面打开 URL页面
window.location.href // 当前页面打开URL页面
this.location.href // 当前页面打开URL页面
location.href // 当前页面打开URL页面
parent.location.href // 在父亲面打开新的连接
top.location.href //在顶层页面打开新页面
分析1: 如果自定义的是 frame 那么将parent、self、top 换成自定义frame 的名称,效 果实在frame 窗口打开url 连接 分析2: window.location.href = window.location.href 和 window.location.reload() 都是刷新当前页面。区别在于是否提交数据,当有提交数据的时候, window.location.reload() 会提示是否提交(面试常问题,如果你是一名PC段开发者) 分析3: window.location.href 直接跳转到指定的url 分析4:window.location.open 肯定被屏蔽掉。 分析5:top.location.href 是最外层的页面的转跳 window.location.href location.href 是本页面的跳转 parent.location.href 是上一层页面转跳 分析6:window.location.href 和 window.open的区别 window.open()是可以在一个网站上打开另外的一个网站的地址 window.location()是只能在一个网站中打开本网站的网页 延伸部分1: reload 方法,该方法强迫浏览器刷新当前页面 。 location.reload(bForceGet) 可选参数,默认是 false,从客户端缓存里面取当前页。当为true ,则是以get 方式,从服务器取最新的页面,相当于F5刷新。 replace 该方法通过指定URL替换当前缓存在历史里的项目,因为使用replace方法后,不能通过前进和后退 来访问已经被替换的URL 。
延伸部分2: http-equiv 属性 --- HTTP 协议的响应报文 此属性出现的在meta 属性中,HTTP 协议的响应头报文 此属性的HTTP协议的响应头报文的值应使用content属性来描述 1.Content-Type Content-Language 显示字符集的设定 <meta http-equiv="Content-Type" Content="text/html; Charset=gb2312″ /> <meta http-equiv="Content-Language" Content="zh-CN" /> 2.refresh 让页面多久刷新自己,或者在多长时间后网页自己转跳到其他页面。 <meta http-equiv="Refresh" Content="30″> <meta http-equiv="Refresh" Content="5; Url=http://www.dalbll.com" /> 3.Expires(期限) 指定网页在缓存中的过期时间,一旦网页过期,必须到服务器上重新调阅 <meta http-equiv="Expires" Content="0″ /> <meta http-equiv="Expires" Content="Wed, 26 Feb 1997 08:21:57 GMT" /> 4.pragma 禁止浏览器从本地的缓存中调阅页面的内容 <meta http-equiv="Pragma" Content="No-cach" />
转载于猿2048:➣《js刷新页面常用方法总结》
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论