There are several ways to reload a page using javascript, but i am going to show you two possibilities that in my opinion arte the best.
In javascript there already exists a function that will automatically reload your page. It is simply called reload():
1 | reload(); |
There is also an other way to do it namley using the window.location object and the href property. This object can be used either to load any page so if you want to reload the page you have to load the existing page. You do this by assigning the current url to window.location.href.
1 | window.location.href="any page you want to load"; |
The window.location object contains all the information about the current url. In oreder to get the current url you have to call window.location.href as well. So the whole reload statement looks like that:
1 | window.location.href=window.location.href; |
Here I prepared a little demo for you.
if you want to reload a page just using plain javascript you can do this the following way:
1 | <a href="" onclick="reload()">reload</a> |
1 | <a href="" onclick="window.location.href=window.location.href">reload</a> |
And if you want to use jQuery you can do this like this:
keep in mind that using JQuery requires to attach the JQuery library first!
1 2 3 4 5 6 7 8 9 10 11 | $(document).ready(function(){ $('#reload_1').click(function(){ reload(); }); $('#reload_2').click(function(){ window.location.href=window.location.href }); }); |
<a href="" id="reload_1">reload</a> <br /> <a href="" id="reload_2">reload</a>
DEMO:

