Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will code be executed after window.location =''

Tags:

javascript

If we have such code:

window.location = 'http://example.net';
$.ajax({...});

Is any chance that the ajax code will be sent? Or there is no chance, that ajax request will be ever executed? thank you

like image 540
Mihey Mik Avatar asked Jun 07 '26 20:06

Mihey Mik


1 Answers

When the location property is altered, the user agent begins to unload the current document in preparation for the loading of the new one. Only code that is registered into the document or window beforeunload or unload events will execute at that point.

like image 72
Scott Marcus Avatar answered Jun 10 '26 10:06

Scott Marcus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!