如何在IE中刷新页面

时间:2012-08-03 05:02:16

标签: javascript-events

如何在IE中使用java脚本刷新页面,以下代码在mozilla中工作但在Internet Explorer中不起作用

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

6 个答案:

答案 0 :(得分:6)

Window.location.href是窗口页面的url。你做了什么,只是在其中重写相同的值,所以浏览器发送另一个GET请求到你的同一个

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

答案 1 :(得分:6)

在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 :(得分:1)

window.location = window.location

答案 3 :(得分:1)

使用 window.location.reload(true);

答案 4 :(得分:0)

使用它:

location.reload();

它应该有用。如果它不起作用,您可能会在页面的其他位置出现错误。

答案 5 :(得分:-1)

应该这样做..

window.location.reload();