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

前端 未结 7 2250
余生分开走
余生分开走 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:55

    You can somehow try this:

    Spawned window:

    window.onunload = function (e) {
        opener.somefunction(); //or
        opener.document.getElementById('someid').innerHTML = 'update content of parent window';
    };
    

    Parent Window:

    window.open('Spawn.htm','');
    window.somefunction = function(){
    
    }
    

    You should not do this on the parent, otherwise opener.somefunction() will not work, doing window.somefunction makes somefunction as public:

    function somefunction(){
    
    }
    

提交回复
热议问题