6
What’s the difference between location.href = url
and the location.assign(url)
? Is it something in Javascript memory consumption? Is there any official recommendation which one to use?
I consider the Location.assign more elegant and readable, but I hope it consumes more memory.
From what I read, the
assign
may issue the exceptionSecurityError
in some situations and thehref
does not care about it. I could not understand right in which situations it would happen. Know something about it?– Woss
I read that he can issue this exception, but found no reference of what to use
location.href
as Setter would not do the same. There is a link saying that href does not care about this?– bfavaretto
I read that href is a little, a little, a little faster. But I still find it very strange in the middle of the code you give a = and it change your page, a function do this is something much more logical for me.
– Luiz Santos
I believe I misunderstood the first reading of the item 5.5.3.1 Security, that would be an exception to
SecurityError
. Now I don’t even know if I understood what I read kkk– Woss
I read that too (in the OS in English), but if the difference is not glaring it may be in the margin of error of the test. It makes sense your reasoning, if you think it clearer you can use the
assign
no problem. @Luizsantos– bfavaretto
@Andersoncarloswoss I think it’s the implementation of CORS control. I keep believing that both end up calling the same algorithm.
– bfavaretto
@Luizsantos the
location.href
is a variable. If you change the variable, theoretically you change what it should show.– Sam
For now I agree with you. The afternoon I will read more calmly and check all these contextual nomenclatures involved. At the time it got confused for me.
– Woss
I ended up using href. I just commented that I find the other more legible. The question was also whether one can be discontinued or something like that. Thank you all very much! :)
– Luiz Santos