When would you set location to a URL string versus setting location.href?
location = "http://www.stackoverflow.com";
vs
location.href = "http://www.stackoverflow.com";
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You might set
locationdirectly because it’s slightly shorter. If you’re trying to be terse, you can usually omit thewindow.too.URL assignments to both
location.hrefandlocationare defined to work in JavaScript 1.0, back in Netscape 2, and have been implemented in every browser since. So take your pick and use whichever you find clearest.