Skip to content Skip to sidebar Skip to footer

How To Know When Popup Is Closed In Javascript

This code will open go.com in popup window:

Solution 1:

How about instead of directly loading that external page in the window, you open up a "local" window with an iframe containing the external page content? That way you still have enough control over the actual window to be able to tell when it's closed.

Some drawbacks: the address bar will not show the URL they are browsing and it may also break if go.com has some sort of frame busting code.

Some example code:

function openIFrameInWindow(url) {
    var myWindow = window.open("");

    var iframe = document.createElement("iframe");
    iframe.src = url;

    myWindow.document.body.appendChild(iframe); 

    myWindow.document.body.onbeforeunload = function () { alert("WINDOW CLOSED") }; 
}

<a href="javascript:void(0)" onClick="javascript:openIFrameInWindow('http://go.com')">open</a>

Solution 2:


Solution 3:


Post a Comment for "How To Know When Popup Is Closed In Javascript"