`
Franciswmf
  • 浏览: 781093 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

window.location.Reload()和window.location.href 区别

 
阅读更多
参考:http://blog.csdn.net/cqkxzyi/article/details/7036908

首先介绍两个方法的语法:

reload 方法,该方法强迫浏览器刷新当前页面。
语法:location.reload([bForceGet])参数: bForceGet, 可选参数, 默认为 false,从客户端缓存里取当前页。 true, 则以GET 方式,从服务端取最新的页面, 相当于客户端点击 F5("刷新")

replace 方法,该方法通过指定URL替换当前缓存在历史里(客户端)的项目,因此当使用replace方法之后,你不能通过“前进”和“后退”来访问已经被替换的URL。
语法:location.replace(URL) 参数: URL

在实际应用的时候,重新刷新页面的时候,我们通常使用: location.reload() 或者是 history.go(0) 来做。因为这种做法就像是客户端点F5刷新页面,所以页面的method="post"的时候,会出现“网页过期”的提示。那是因为Session的安全保护机制。可以想到: 当调用 location.reload() 方法的时候, aspx页面此时在服务端内存里已经存在, 因此必定是 IsPostback 的。如果有这种应用: 我们需要重新加载该页面,也就是说我们期望页面能够在服务端重新被创建, 我们期望是 Not IsPostback 的。这里,location.replace() 就可以完成此任务。被replace的页面每次都在服务端重新生成。你可以这么写: location.replace(location.href)
=======================================================
<a onclick="javascript:window.location.href=window.location.href;">
<a onclick="javascript:window.location.reload();">

测试效果一样。表单没有提交。

<input type="submit" onclick="javascript:window.location.reload();" value="单击" id="btnVCode" />
<input type="submit" onclick="javascript:window.location.href=window.location.href;" value="单击" id="btnVCode" />

都提交数据



window.location.Reload()应该是刷新.(如果有数据提交的话,会提示是否提交的(是和否选项))
window.location.href=window.location.href; 是定向url提交数据

最好不要用location.reload(),而用location=location比较好,还有在模式窗口(showModalDialog和showModelessDialog)前者不能用。
reload参数有true和false,比较有意思?
避免重复提交:
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
     {
         if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
         {
             string nr = ((DataRowView)e.Item.DataItem).Row["GZZDS"].ToString();
             string id = ((DataRowView)e.Item.DataItem).Row["RZID"].ToString();
             string rid = ((DataRowView)e.Item.DataItem).Row["RWXH"].ToString();
             string link = "";

            if (nr == "")
             {
                 link = "<a href='#' onclick=\"selectGuide2('BookDoc.aspx?type=2&Id=" + id + "&rid=" + rid + "&Rnd='+Math.random());location=location;\">选择指导书</a>";
             }
             else
             {
                 string t = (ViewState["State"].ToString() == "Query" || ((DataRowView)e.Item.DataItem).Row["GZZT"].ToString() == "工作结束") ? "false" : "true";
                 string path=((DataRowView)e.Item.DataItem).Row["GZZDSPath"].ToString();              

                link = "<a href='#' onclick=\"EditWord('" + path + "'," + t + ")\">" + nr + "</a>";
             }

            ((Literal)e.Item.FindControl("Literal1")).Text = link;
         }
     }

window.location.Reload()和window.location.href  window.location.Reload()应该是刷新.(如果有数据提交的话,会提示是否提交的(是和否选项))
window.location.href=window.location.href;
是定向url提交数据
是大的区别还是是否提交数据了
function refresh()
{
//刷新页面函数
//window.focus();刷新窗口
//document.execCommand("Refresh");刷新窗口
//self.location.reload();刷新当前窗口
parent.location.reload();刷新父窗口
//aaa.location.reload();弹出窗口刷新父窗口
}  
使用window.location.replace() or window.location.href(), 来重新加载此页面不出现提示框
分享到:
评论

相关推荐

    jsp 刷新父页面

    window.opener.location.href = window.opener.location.href 刷新以winodw.showModelDialog()方法打开的窗口 window.parent.dialogArguments.document.execCommand('Refresh'); 或 Response.Write("&lt;script&gt;...

    [removed].reload 刷新使用分析(去对话框)

    使用[removed].reload;...window.opener.location.href=window.opener.location.href; window.opener.location.reload(); 这种写法就不出现那讨厌的对话框啦! 介绍JS实现刷新iframe的方法 &lt;iframe src=”1.ht

    JS刷新框架外页面七种实现代码

    window.parent.frames[1].location.reload(); 语句2. window.parent.frames.bottom.location.reload(); 语句3. window.parent.frames[“bottom”].location.reload(); 语句4. window.parent.frames.item(1)....

    关闭时刷新父窗口两种方法

    window.opener.location.... 但[removed].Reload 如果有数据提交的动作,会提示是否提交的(是和否选项) window.opener.location.href=window.opener.location.href 是定向url提交数据,则不会出现是和否 的选择框。

    JS窗口大全----很全的哦

    提交" onclick="javaScript:window.location.href='http://angelialily.javaeye.com/';"/&gt; //-----------关闭按钮----------// 关闭" onclick="javaScript:window.close();"&gt; //-----------返回并关闭连接-----...

    Javascript刷新页面的实例

    Javascript刷新页面的实例 ...2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand(‘Refresh’) 6 window.navigate(location) 7 location.replace(location)

    JS刷新父页面 父窗口

    // 刷新父页面。此段代码放在被弹出的页面 function refreshOpener() { ... if (win.opener) win.opener.location.reload();//或parent.location.reload(); } catch (ex) { } } ......................

    window.open的页面如何刷新(父页面)上层页面

    代码如下: this.ClientScript.RegisterStartupScript(this.GetType(), this.Title, “window.opener.location.reload();alert&#40;‘销帐成功!’&#41;;”, true); 主要是这段js代码:window.opener.location.reload...

    刷新页面的几种方法小结(JS,ASP.NET)

    Javascript刷新页面的几种方法: 1. history.go(0) 2.... document.URL=location.href 自动刷新页面的方法: 1.页面自动刷新:把如下代码加入&lt;head&gt;区域中 &lt;meta http-equiv=”refresh”

    JS中表单的使用小结

    使用window.open()弹出的弹出窗口,刷新父窗口 window.opener.location.reload() 使用window.showDialog弹出的模式窗口 window.dialogArguments.location.reload(); 2.javascript弹出窗口的两种实现方式 —下面给...

    子窗体与父窗体传值示例js代码

    //获取父页面 //parent.location.reload(); //刷新父页面 if (parent != null && parent != “undefined”) { window.returnValue = value; //返回值 window.close(); //关闭子页面 } //window.opener.document....

    107个常用javascript语句

    24.指定当前显示链接的位置:window.location.href="URL" 25.取出窗体中的所有表单的数量:document.forms.length 26.关闭文档的输出流:document.close(); 27.字符串追加连接符: = 28.创建一个文档元素:document....

    layer 刷新某个页面的实现方法

    window.parent.location.reload()//刷新父页面 var index = parent.layer.getFrameIndex(window.name)//获取窗口索引 parent.layer.close(index) 1:刷新父页面 2:关闭此页面 2.1 获取窗口索引 (parent.window....

    JAVASCRIPT下判断IE与FF的比较简单的方式

    但是过程相对复杂一点,当我们只需要一个简单的判断方式时,可以这样做: 代码如下:[removed] if (document.all){ //IE window.dialogArguments.location.reload(); }else{ //FIREFOX opener.location.reload(); } ...

    javascript函数的解释

    24.指定当前显示链接的位置:window.location.href="URL" 25.取出窗体中的所有表单的数量:document.forms.length 26.关闭文档的输出流:document.close(); 27.字符串追加连接符:+= 28.创建一个文档元素:document....

    JavaScript权威指南

    The Location Object Section 13.10. The History Object Section 13.11. Multiple Windows and Frames Chapter 14. The Document Object Section 14.1. Document Overview Section 14.2. Dynamically ...

    JS中showModalDialog关闭子窗口刷新主窗口用法详解

    网上找了好长时间 大都是window.opener.location.reload(),等等 都不是我想要的 最后终于发现了一个 想知道的就往下看看吧 showModalDialog和showModelessDialog 一、showModalDialog和showModelessDialog有什么不同...

    JavaScript刷新页面大全

    详细的介绍了JavaScript多种情况下脚本刷新页面的的方法,并有详细的代码示例。如:window.location.reload();

    javascript小技巧

    window.onresize=new Function("window.location.reload()") } function setmessage2(){ topmsg=new Layer(window.innerWidth) topmsg.bgColor=backgroundcolor regenerate2() topmsg.document.write(message) ...

    JS刷新父窗口的几种方式小结(推荐)

    浮层内嵌iframe及frame集合窗口,刷新父页面的多种方法 [removed] parent.location.reload(); [removed] [removed] ... window.opener.location.reload(); [removed] [removed] window.opener.location.

Global site tag (gtag.js) - Google Analytics