Difference between window.location and location.href

window.location is an object that holds all the information about the current document location (host, href, port, protocol etc.).

location.href is shorthand for window.location.href (you call location from global object – window, so this is window.location.href), and this is only a string with the full URL of the current website.

They act the same when you assign a URL to them – they will redirect to the page which you assign, but you can see differences between them when you open the browser console (firebug or developer tools) and write window.location and location.href.

Leave a Comment