开发者

How does or is it possible for a browser keep track of a pop up window

开发者 https://www.devze.com 2023-02-14 05:02 出处:网络
I noticed when using the Google Chat feature from your Google Mail that you can pop out a chat into its\' own window. Then when I went to close the Google Mail window开发者_开发百科 it warned that oth

I noticed when using the Google Chat feature from your Google Mail that you can pop out a chat into its' own window. Then when I went to close the Google Mail window开发者_开发百科 it warned that other windows would also be closed if I continued and then showed a list of the windows. How is this done? Is it possible to track whether a window you invoked has been closed?


Yes, when you do a window.open in JavaScript, you can set it to a var like:

myWindow = window.open(...)

Then you could bind events to that window like:

myWindow.onUnload = funcWindowClosed;

You could keep track of multiple pop-up windows by putting them into an array.

You can also call JavaScript functions in the parent window by the child (pop-up) window using:

window.opener


If you assign each new window a name when u make them a popup and then with php (or anything else) save the name of the window to a cookie or a session, you can then close all of the popups created by your site when a certain action is taken:

this is what i do (in php/js):

function closePopups(){
    var popups = Array();
    <?
    $i = 0;
    if(isset($_SESSION['popups'])){
        foreach($_SESSION['popups'] as $key=>$pop){
            echo "popups[$i] = '$pop';\n";
            $i++;
        }
        unset($_SESSION['popups']);
    }
?>
    for( i = 0; i < popups.length; i++ ){
        window.open('',popups[i],'width=1,height=1').close();
    }
}

In the for loop you have to open the popup first and then close it so that way your current window can see if a popup with that name was already opened, and if it was, than it will close it. If it wasn't it will create a new window with the same name and immediately close it.

This is how i soleved the issue

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号