html - Should I use window.navigate or document.location in JavaScript?

ID : 20167

viewed : 27

Tags : javascripthtmlnavigationjavascript

Top 5 Answer for html - Should I use window.navigate or document.location in JavaScript?

vote vote

90

window.location.href = 'URL'; 

is the standard implementation for changing the current window's location.

vote vote

82

window.navigate not supported in some browser

In java script many ways are there for redirection, see the below code and explanation

window.location.href = "http://krishna.developerstips.com/"; window.location = "http://developerstips.com/"; window.location.replace("http://developerstips.com/"); window.location.assign("http://work.developerstips.com/"); 

window.location.href loads page from browser's cache and does not always send the request to the server. So, if you have an old version of the page available in the cache then it will redirect to there instead of loading a fresh page from the server.

window.location.assign() method for redirection if you want to allow the user to use the back button to go back to the original document.

window.location.replace() method if you want to want to redirect to a new page and don't allow the user to navigate to the original page using the back button.

vote vote

76

window.location also affects to the frame,

the best form i found is:

parent.window.location.href 

And the worse is:

parent.document.URL  

I did a massive browser test, and some rare IE with several plugins get undefined with the second form.

vote vote

67

window.location will affect to your browser target. document.location will only affect to your browser and frame/iframe.

vote vote

56

document.location is a (deprecated but still present) read-only string property, replaced by document.URL.

Top 3 video Explaining html - Should I use window.navigate or document.location in JavaScript?

Related QUESTION?