In this tutorial i will let u know difference between window.location.href
and window.open()
, both are very important way to redirect user to a target location,both function are commonly used by web developer.
I have explianed below about difference Between Window.location.href
and Window.open ()
methods in JavaScript.
Simple use and Example of window.open()
method
This a JavaScript method, it takes a target URL as a parameter where you want to redirect user. This function also have many optional parameters. This method will open target URL in new window on browser.
For example:
window.open('http://google.com');
Simple use and Example of window.location.href
method
This is not a method, it’s a property .This property tell to you the current URL location of the browser. This property used to set target URL and user will redirect the page in same window.
window.location.href = 'http://google.com';