Reputation: 37068
I'm wondering what the arguments are for using one vs the other. I am familiar with the other properties like window.location.pathname
. But as far as I can tell, assigning to window.location
has identical behavior to calling window.location.assign
and passing it the url.
Why use one or the other? I prefer assign
because it's more explicit whereas assigning to window.location
has implicit, veiled magic in its setter.
Is there an argument for one or the other?
Upvotes: 0
Views: 344
Reputation: 5815
It's the same:
Whenever a new value is assigned to the location object, a document will be loaded using the URL as if location.assign() had been called with the modified URL. Note that security settings, like CORS, may prevent this to effectively happen. (https://developer.mozilla.org/en-US/docs/Web/API/Window/location)
Upvotes: 1