Register now or log in to join your professional community.
window.location.href is not a method, it's a property that will tell you the current URL location of the browser. Setting the property to something different will redirect the page.
Example:
window.location.href = 'http://www.google.com'; //Will take you to Google.
window.open() is a method that you can pass a URL to that you want to open in a new window.
Example:
window.open('http://www.google.com'); //This will open Google in a new window.
window.location.href is not a method, it's a property that will tell you the current URL location of the browser. Setting the property to something different will redirect the page.
window.open() is a method that you can pass a URL to that you want to open in a new window. For example:
window.location.href example:
window.location.href = 'http://www.google.com'; //Will take you to Google.
window.open() example:
window.open('http://www.google.com'); //This will open Google in a new window.
Window.location.href using to redirect specified page in same window.
Window.Open it open a new window or new tab and we can manage nature, height, width,etc.
one is a property and the other is method :)
Key differences between window.location and window.open are:
Window.Open
- It is a method.
- It accepts few parameters like window.open(URL,name,specs,replace).
- It accepts a URL and opens it to a new window.
- For example http://www.w3schools.com/jsref/met_win_open.asp
Window.location.href
- It is not a method but a string representation.
- It returns the location of the current page.