Is there a way to have an onload callback after changing window.location.href?
问题 Essentially what I'd like to do is something to the effect of this: window.location.href = "some_location"; window.onload = function() { alert("I'm the new location and I'm loaded!"); }; Is there any way to have a callback when the window's new location is loaded? (The above code doesn't work.) 回答1: 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