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.
window.open() : 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:
1 |
window.open('http://google.com');
|
window.location.href : 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.
1 |
window.location.href = 'http://google.com';
|