javascript - 如何在 IE 中刷新页面

标签 javascript internet-explorer dom-events page-refresh

如何在 IE 中使用 Javascript 刷新页面?以下代码在 Mozilla 中有效,但在 Internet Explorer 中无效

window.location.reload());
history.go(0);

最佳答案

在 javascript 中,您可以使用:

location.reload(); => post request, same as click the refresh button on the browser
window.location=window.location; => get request
self.location=self.location; => get request

如果您收到 IE 错误提示

'要重新显示网页,Internet Explorer 需要重新发送您之前提交的信息' ,

你可以使用 window.location=window.location;刷新页面而不是 location.reload();

实现:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="PostMethod_Test._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="litJavascript" runat="server"></asp:Literal>
<div>
Refresh:
<div>
Get/Post Method:<a href="javascript:location.reload();">JS Location Reload</a> (if
there is any control in the form then after the form was submitted for the first
time, if you click this, it will be a post method coming with the IE alert)
</div>
<div>
Get Method:<a href="javascript:window.location=window.location;">JS Window Location</a>
(does not create a history entry) (if there is any control in the form then after
the form was submitted for the first time, if you click this, it will still be a
get method which means the form will not be submitted again)
</div>
<div>
Get Method:<a href="javascript:self.location=self.location;">JS Self Location</a>
(Same as above)
</div>
<div>
Get/Post Method: IE Refresh button - same as location.reload()
</div>
</div>
<hr />
<div>
Open New Window:
<div>
No Method:<a href="javascript:var a = window.open('webform1.aspx');">JS Window Open</a>
(just open)
</div>
<div>
Post Method for parent page:<asp:Button ID="btnOpen" Text="Open Window" runat="server"     />
</div>
</div>
</div>
</form>
</body>
</html>

关于javascript - 如何在 IE 中刷新页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11789555/

相关文章:

javascript - 如何从 "Bootstrap Datepicker"获取当前 viewMode 属性

javascript - 从选择框传递文本数据

html - ie元标签触发边缘模式的最佳位置

javascript - 如何为 KnockoutJS 中的单击事件维护引用正确的执行上下文?

javascript - 拦截浏览器中的所有 UI 事件

javascript - 无需滚动的 Wordpress Jquery 动画

javascript - 如何将方法添加到多个变量

javascript - 正则表达式代码在 Internet Explorer 上不起作用

html - 翻转框动画适用于除 Safari 和 IE 之外的所有浏览器

JavaScript 事件覆盖