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

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(), 来重新加载此页面不出现提示框

最新文章

  1. PHP中PDO事务的使用方法
  2. Ubuntu 下,修改 Mac address
  3. 【抄】更改eclipse配置
  4. EDW on Hadoop(Hadoop上的数据仓库)技术选型和实践思考
  5. Myeclipse8.5 最新注册码以使用方法(可以用到2015年!!!)
  6. phpstorm相关设置
  7. 关于Reapter多重嵌套的详细补充
  8. VS2013的项目转到VS2010需要修改的
  9. SSO单点登录
  10. exec 和 source的区别
  11. VBA.NET 系统可行性分析模板
  12. JS声明变量的写法
  13. java核心-多线程-线程类-Callable、Future和FutureTask
  14. 迁移桌面程序到MS Store(5)——.NET Standard
  15. 【转】MVC中code first方式开发,数据库的生成与更新(Ef6)
  16. GIT版本控制工具总结
  17. According to TLD or attribute directive in tag file, attribute items does not accep t any expressions
  18. kindle paperwhite3 连不上WIFI解决方法
  19. Mysql报错......\xE6\x80\xBB\xE7\x9B\x91&#39; for column...
  20. 01、前端需要注意哪些SEO?

热门文章

  1. Bluebird-Collections
  2. 把数组A的奇数放在左边,偶数放在右边
  3. git(osx)上的一个git commit无法正确提交的问题
  4. delphi 2010 导出sql server 数据到DBF乱码问题
  5. 转】使用log4jdbc记录SQL信息
  6. HD2025查找最大元素
  7. cvc-elt.1: Cannot find the declaration of element &#39;beans&#39;
  8. IIS6.0禁止用户下载txt文件
  9. 一个人写的操作系统 - Sparrow OS
  10. UI:自定义键盘的实现