Differenece between window.location and location.href
Question by Rizwan Shahid
I am getting confused what is difference between window.location
and location.href
both are acting in same way
Answer by Mateusz W
Not really.
window.location
is object that holds all information about 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 string with full url to current website.
They acting the same when you assign url to them – this will redirect to page which you assing, but you can see difference between them, when you open console (firebug, of developer tools) and write window.location
and location.href
.
Answer by Starx
location.href
property returns the entire URL of the current page.
Where as
window.location
property represents the currect location of the window object, if you change this you will get redirected.