chimerical chimerical - 2 years ago 73
Javascript Question

Javascript: Setting location.href versus location

When would you set

to a URL string versus setting

location = "";


location.href = "";


Answer Source

You might set location directly because it's slightly shorter. If you're trying to be terse, you can usually omit the window. too.

URL assignments to both location.href and location are 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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download