1

Why is the behavior different between Chrome and IE11 when making two window.location.href assignments in a row?

Chrome ignores the first assignment and will only issue a request for the last one.
IE11 will send a request for the both.

Repro'd here.
NOTE: You'll need to use a tool that can track the outbound requests like fiddler or similar to see the request go out on IE11.

2
  • here are more info on assigning multiple handlers to an event: stackoverflow.com/questions/1491718/… As stated in Brad's answer below, browsers do behave differently; it's gradually getting better, though
    – Manube
    Commented Jul 10, 2016 at 6:48
  • @Manube I would argue in this case that the differences between the browsers is totally fine. I can't think of any circumstance where someone would expect the browser to not go to the next URL as instructed by their code. And, it's not as if the JS app has to do anything, as it's expected to be destroyed by will of the user at any time.
    – Brad
    Commented Jul 10, 2016 at 6:58

1 Answer 1

4

It's up to the browser how to implement things like setting the location. One browser probably begins tearing down immediately, and the other probably continues running JavaScript until it's time for the next page to load. In Chrome, it is probably making both requests but the first is cancelled so quickly that it never actually makes it out of the browser.

Not the answer you're looking for? Browse other questions tagged or ask your own question.