How to run function of parent window when child window closes?

前端 未结 7 2266
余生分开走
余生分开走 2020-11-29 02:15

I am calling the javascript window.open() function to load another url in a pop up. Once the users is finished it takes them to the last page that has a link that says close

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 02:56

    The answers as they are require you to add code to the spawned window. That is unnecessary coupling.

    // In parent window
    var pop = open(url);
    pop.onunload = function() {
      // Run your code, the popup window is unloading
      // Beware though, this will also fire if the user navigates to a different
      // page within thepopup. If you need to support that, you will have to play around
      // with pop.closed and setTimeouts
    }
    

提交回复
热议问题