There are several methods in javascript for redirecting a user to different page in the current browser window.
Two of them are as follow
- location.href
- location.replace
location.href:- If we use following script then the user will be redirected to http://www.findnerd.com page immediately.
location.href='http://www.findnerd.com';
location.replace Method:- If we use following script then the user will be redirected to http://www.findnerd.com page immediately.
location.replace('http://www.findnerd.com/');
The difference between location.href and location.replace
Though both obtains the same results for display purpose, they are different in functionality. The difference between location.href and location.replace is that the location.href creates a new history entry on the browser meaning that if they hit the back button, they can get in a 'redirection loop' which is usually undesirable and may have unwanted side effects while location.replace does not add any new history entry on the browser.
0 Comment(s)