How to refresh the page by using Javascript in IE? Following code is working in Mozilla but not in Internet Explorer
window.location.reload());
history.go(0);
How to refresh the page by using Javascript in IE? Following code is working in Mozilla but not in Internet Explorer
window.location.reload());
history.go(0);
Share
Improve this question
edited Jul 29, 2021 at 16:55
Brian Tompsett - 汤莱恩
5,88372 gold badges61 silver badges133 bronze badges
asked Aug 3, 2012 at 5:02
sayeed gurusayeed guru
411 gold badge1 silver badge2 bronze badges
1
- Did you get any working answer? .. tried all below answers but none is working. – NMathur Commented Sep 23, 2017 at 9:07
6 Answers
Reset to default 7In javascript you can use:
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
If you get an IE error saying
'To display the webpage again, Internet Explorer needs to resend the information you've previously submitted',
you can use window.location=window.location; to refresh the page instead of location.reload();
Implementation:
<%@ 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>
Window.location.href is the url of the window page. What you do, is just rewrite the very same value in it, so the browser send another GET request to the very same ur
window.location.href = window.location.href;
window.location = window.location
Use window.location.reload(true);
use this:
location.reload();
it should work. If it's not working you might have an error somewhere else in your page.
This should do it..
window.location.reload();