2

Consider following code sample in <script></script> block in a simple HTML page.

//synchronous
location.href = 'https://google.com';
console.log('test');

or

//asynchronous
location.href = 'https://google.com';
setTimeout(() => console.log('test'));

In both cases it still prints 'test' message in console, before location is changed.

Why does it happen? How to tell exactly where JS execution will stop in current site, before it resets and new global JS context will start?

Is it even determinable process, or completely random, depending on speed of loading of site in new location?

setec
  • 15,506
  • 3
  • 36
  • 51
  • https://stackoverflow.com/questions/10525584/what-happens-to-code-after-a-javascript-redirect-setting-window-location-href – Slai Nov 19 '19 at 11:39

0 Answers0