【js 方法】js 页面刷新location.reload和location.replace的区别 【转】
【转】:http://zccst.iteye.com/blog/2162658
reload 方法,该方法强迫浏览器刷新当前页面。
语法: location.reload([bForceGet])
参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前页。true, 则以 GET 方式,从服务端取最新的页面, 相当于客户端点击 F5("刷新")
replace 方法,该方法通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后退”来访问已经被替换的URL。
语法: location.replace(URL)
在实际应用的时候,重新刷新页面的时候,我们通常使用: location.reload() 或者是 history.go(0) 来做。因为这种做法就像是客户端点F5刷新页面,所以页面的method="post"的时候,会出现“网页过期”的提示。那是因为Session的安全保护机制。可以想到: 当调用 location.reload() 方法的时候, aspx页面此时在服务端内存里已经存在, 因此必定是 IsPostback 的。如果有这种应用: 我们需要重新加载该页面,也就是说我们期望页面能够在服务端重新被创建, 我们期望是 Not IsPostback 的。这里,location.replace() 就可以完成此任务。被replace的页面每次都在服务端重新生成。你可以这么写: location.replace(location.href)
replace函数在设置URL方面与location的href属性或assign函数完全一样,但是它会删除history对象的地址列表中的URL,从而使go或back等函数无法导航。
例子:
<a class="btn btn-success radius r mr-20" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont"></i></a>
下面是相关的应用与知识点:
window.location.href
window.top.location.replace("http://www.jb51.net")
top.location.href("http://www.jb51.net")
window.navigate ("http://www.jb51.net")
Html:
<meta http-equiv="Refresh" content="0; url=http://baidu.com/" >
---------------------------------------
URL 即:统一资源定位符 (Uniform Resource Locator, URL)
完整的URL由这几个部分构成:
scheme://host:port/path?query#fragment
下面介绍:
1》》》scheme:
通信协议 常用的http,ftp,maito等
2》》》host:主机
服务器(计算机)域名系统 (DNS) 主机名或 IP 地址。
3》》》port:端口号
整数,可选,省略时使用方案的默认端口,如http的默认端口为80。
4》》》path:路径
由零或多个"/"符号隔开的字符串,一般用来表示主机上的一个目录或文件地址。
5》》》query:查询
可选,用于给动态网页(如使用CGI、ISAPI、PHP/JSP/ASP/ASP.NET等技术制作的网页)传递参数,可有多个参数,用"&"符号隔开,每个参数的名和值用"="符号隔开。
6》》》fragment:信息片断
字符串,用于指定网络资源中的片断。例如一个网页中有多个名词解释,可使用fragment直接定位到某一名词解释。(也称为锚点.)
举例子:
对于这样一个URL
http://www.jb51.net:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere
我们可以用javascript获得其中的各个部分
1, window.location.href
整个URl字符串(在浏览器中就是完整的地址栏)
本例返回值: http://www.jb51.net:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere
2,window.location.protocol
URL 的协议部分
本例返回值:http:
3,window.location.host
URL 的主机部分
本例返回值:www.jb51.net
4,window.location.port
URL 的端口部分
如果采用默认的80端口(update:即使添加了:80),那么返回值并不是默认的80而是空字符
本例返回值:""
5,window.location.pathname
URL 的路径部分(就是文件地址)
本例返回值:/fisker/post/0703/window.location.html
6,window.location.search
查询(参数)部分
除了给动态语言赋值以外,我们同样可以给静态页面,并使用javascript来获得相信应的参数值
本例返回值:?ver=1.0&id=6
7,window.location.hash
锚点
本例返回值:#imhere
【js 方法】js 页面刷新location.reload和location.replace的区别 【转】的更多相关文章
- js返回到上一个页面刷新与不刷新的写法
返回上个页面刷新: <script>window.location.href=document.referer</script> 返回上个页面不刷新 <script> ...
- javascript:location.reload()和location.replace()的区别,及对图片缓存的影响。
有段时间没有清理IE的临时文件(缓存文件),在我清理的时候,我突然发现一个问题. 我打开的一个网站,图片默认缓存一个月的,但我发现,当我上传图片或删除图片之后,图片重新缓存,也就意味着,在我上传新图片 ...
- window.location.reload(false);window.location.reload(true);history.Go(0)区别
在日常工作中常用的页面刷新方式的区别: 1 window.location.reload(false); 先说说window.location.reload(false);当我们window.loc ...
- js 页面刷新location.reload和location.replace的区别小结
reload 方法,该方法强迫浏览器刷新当前页面. 语法: location.reload([bForceGet]) 参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前 ...
- js关闭子页面刷新父页面
一.打开方式为window.open window.opener.location.reload(); 二.打开方式为window.showModalDialog 首先在打开时的时候要设置window ...
- JS 控制子页面刷新父页面
iframe里面的子页,用parent.location.href = parent.location.reload();如果是window.open 打开就用opener.location.relo ...
- 常用的兼容IE和火狐FF等浏览器的js方法(js中ie和火狐的一些差别)
介绍了网页上常用的IE/火狐兼容性该页的做法,并给出了代码,相当实用了.为了方便大家阅读代码,以下以 IE 代替 Internet Explorer,以 MF/FF 代替 Mozzila Firefo ...
- ivew 【provide/inject] 页面刷新实现reload
1.App.vue <template> <div id="app"> <router-view v-if="isRouterAlive&q ...
- 利用firebug 查看JS方法, JS 调试
“DOM” 可以查看变量和方法. “脚本”可以用来调试js方法. 有空总结一下白鹤堂老师的最牛JavaScript.
随机推荐
- How to call getClass() from a static method in Java?
刚才在学习Java 使用properties类,遇到这样的错误: Cannot make a static reference to the non-static method getClass() ...
- ffmpeg-20160806-bin.7z
ESC 退出 0 进度条开关 1 屏幕原始大小 2 屏幕1/2大小 3 屏幕1/3大小 4 屏幕1/4大小 S 下一帧 [ -2秒 ] +2秒 ; -1秒 ' +1秒 下一个帧 -> -5秒 f ...
- Django~queries
API queries create, retrieve, update and delete
- hiho一下第二周 Trie树
题目链接:http://hihocoder.com/problemset/problem/1014 #include <iostream> #include <cstdio> ...
- 【leetcode】Convert Sorted Array to Binary Search Tree (easy)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 有序 ...
- mysql常用函数整理
一.数学函数 数学函数主要用于处理数字,包括整型.浮点数等. ABS(x) 返回x的绝对值 ) -- 返回1 CEIL(x),CEILING(x) 返回大于或等于x的最小整数 SELECT CEIL( ...
- August 19th 2016 Week 34th Friday
Friends are not the people you meet at the top, they are the people who were with you at the bottom. ...
- Tomcat在Linux上的安装与配置
以下使用的Linux版本为: Redhat Enterprise Linux 6.5 x86_64,Tomcat版本为tomcat-7.0.54. 1.下载JDK与Tomcat. jdk下载地址 ...
- self和parent的用法
总结 self , parent 的用法 只能用在类的内部 self 本类 (不要理解成本对象) parent 父类 在引入自身的静态属性/静态方法 以及父类的方法时 ...
- Kl 证明 凸函数
回到随机变量传输问题,假设传输中我们不知道具体 分布情况(unknown),我们用一个已知的分布 ,来模拟它,那么在这种情况下如果我们利用 尽可能高效的编码,那么我们平均需要多少额外的信息量来描述x呢 ...