Is there a way to have an onload callback after changing window.location.href?

No, you cannot do it the way you want. Loading a new page closes the current document and starts loading a new document. Any code in your current document will no longer be active when the new page starts to load.

To have an event handler when the new document loads, you would either need to insert code into the new page’s document or load the new document into an iframe and monitor the loading of the iframe from your current document.

Leave a Comment