【问题标题】:How to refresh the page in IE如何在 IE 中刷新页面
【发布时间】:2012-08-03 05:02:16
【问题描述】:

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

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

【问题讨论】:

  • 你得到任何有效的答案了吗? ..尝试了以下所有答案,但没有一个有效。

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


【解决方案1】:

在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>

【讨论】:

    【解决方案2】:

    Window.location.href 是窗口页面的 url。您所做的只是重写其中相同的值,因此浏览器会向相同的 ur 发送另一个 GET 请求

    window.location.href = window.location.href;
    

    【讨论】:

    • 也许对正在发生的事情做一些解释
    • Window.location.href 是窗口页面的url。你所做的只是重写其中相同的值,因此浏览器向相同的 url 发送另一个 GET 请求。
    【解决方案3】:
    window.location = window.location
    

    【讨论】:

      【解决方案4】:

      使用window.location.reload(true);

      【讨论】:

        【解决方案5】:

        使用这个:

        location.reload();
        

        它应该工作。如果它不起作用,您可能在页面的其他地方出现错误。

        【讨论】:

          【解决方案6】:

          应该这样做..

          window.location.reload();
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-05-22
            • 2012-03-07
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-08-04
            • 2012-08-26
            相关资源
            最近更新 更多