Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Difference between location.href and location.replace

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 221
    Comment on it

    There are several methods in javascript for redirecting a user to different page in the current browser window.

    Two of them are as follow

    1. location.href
    2. 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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: