Possible Duplicate:
Javascript: Setting window.location.href versus window.location
When I tested these code in browser it seems like they are the same. Is there any difference?
1
window.location = "http://stackoverflow.com";
2
window.location.href = "http://stackoverflow.com";
Yes, there is a difference.
window.locationis aLocationobject.window.location.hrefis a string representation of the location. Thelocationobject’stoString()value is the same as thehrefproperty, so they are identical if used as strings. Settingwindow.locationis the same as settingwindow.location.href.window.location, however, has several other properties you can use, such aslocation.hostname,location.pathnameandlocation.hash. So you could could setlocation.hashon its own to alter the hash value.