Is there a way to have an onload callback after changing [removed].href?

后端 未结 2 1284
失恋的感觉
失恋的感觉 2020-12-03 13:54

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 th         


        
2条回答
  •  清歌不尽
    2020-12-03 14:07

    Setting window.location.href to a new value tells the browser to simply go to the next page.

    Like so:

    window.location.href = "http://www.google.com/";
    

    Once the browser goes to google.com, that's it, your Javascript is no longer executing, and there is no way for you to have any sort of callback, because the browser is no longer running your page.

    So, the answer is no.

提交回复
热议问题