I am trying to refresh the browser window using the following code:
window.location = window.location.href;
but it doesn't refresh the window, however when I try to do this:
window.location = "http://www.google.com";
It does redirect me to Google. Can anyone please tell me what I am doing wrong here? Why doesn't it refresh the browser window?
Use window.location.reload()
, it does exactly that.
location.reload(forceGet)
can do the trick. Also, you can set the parameter forceGet to true
so that it reloads the page from the server and not from the browser cache. Doing this solve me some issues with IE11 and Edge. By default (location.reload()
) will reload from the cache.
Read: http://www.w3schools.com/jsref/met_loc_reload.asp
In the past I did something like window.location = ''
to refresh the current page but faced issues (wasn't getting the complete url) with Edge and IE 11 even though it worked well on all other major browsers. So I eventually used location.reload(true)
to get to work on Edge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With