Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are possible differences between window.location.reload() and window.location = document.URL? [duplicate]

Tags:

javascript

What is the difference between JavaScript's

window.location.href = window.location.href

and

window.location.reload()

functions?

like image 322
Brian Avatar asked Mar 08 '10 22:03

Brian


People also ask

What is the difference between location reload () and window location reload ()?

Using window. reload() method to reload or refresh the current page. location. reload(true/false) method takes a parameter to determine how the page should be reloaded. True:- Will reload the page from server(uncached).

What is the difference between window location and document location?

window. location is read/write on all compliant browsers. document. location is read-only in Internet Explorer (at least), but read/write in Gecko-based browsers (Firefox, SeaMonkey).

What's the difference between window location and document location in Javascript?

The window. location is read/write on all compliant browsers. The document. location is read-only in Internet Explorer but read/write in Firefox, SeaMonkey that are Gecko-based browsers.

What is the difference between location assign () and location replace ()?

The replace() method of the Location interface replaces the current resource with the one at the provided URL. The difference from the assign() method is that after using replace() the current page will not be saved in session History , meaning the user won't be able to use the back button to navigate to it.


2 Answers

If I remember correctly, window.location.reload() reloads the current page with POST data, while window.location.href=window.location.href does not include the POST data.

As noted by @W3Max in the comments below, window.location.href=window.location.href will not reload the page if there's an anchor (#) in the URL - You must use window.location.reload() in this case.

Also, as noted by @Mic below, window.location.reload() takes an additional argument skipCache so that with using window.location.reload(true) the browser will skip the cache and reload the page from the server. window.location.reload(false) will do the opposite, and load the page from cache if possible.

like image 189
David Johnstone Avatar answered Oct 11 '22 18:10

David Johnstone


If you say window.location.reload(true) the browser will skip the cache and reload the page from the server. window.location.reload(false) will do the opposite.

Note: default value for window.location.reload() is false

like image 36
Mic Avatar answered Oct 11 '22 18:10

Mic