How can I detect my pop up window being closed by the visitor?var WinId = window.open('popup.htm')
if (!WinId.opener) WinId.opener = self;

解决方案 »

  1.   

    skyyoung
    我想开一个新窗口
    然后再由原来的网页控制新窗口
    但在控制前就要肯定新窗口还存在
    所以现在的问题是怎么检查一个新的窗口是否存在
    你用的方法和我一样的
    这样只是在窗口存在时才能用的
    当窗口不存在时
    if (!WinId.opener) WinId.opener = self;
    在检查WinId.opener时就会出错
    错误是远端伺服器不存在或无法使用 
      

  2.   

    <SCRIPT LANGUAGE="JavaScript"><!--
    function newWindow(file,window) {
        msgWindow=open(file,window,'resizable=no,width=200,height=200');
        if (msgWindow.opener == null) msgWindow.opener = self;
    }
    //--></SCRIPT>写多了个null行不行
      

  3.   

    行不行
    How can I check that a popup window is still open before attempting to close it?You can check to see if the window has been opened then subsequently closed with: <script language="JavaScript"><!--
    var windowHandle = null;function openWindow() {
        windowHandle = window.open('http://www.irt.org/','windowName','height=200,width=200');
        if (!windowHandle.closed)
            window.closed = false;
    }function closeWindow() {
        if (windowHandle != null) {
            if (windowHandle.closed) {
                // already opened and closed
            }
            else {
                windowHandle.closed = true;
                windowHandle.close();
            }
        }
        else
            // not yet opened
    }
    //--></script> Micke Kazarnowicz writes: The original didn't work (generated error messages in IE 5.0) and worked only once in Netscape 4.7. This one [following] doesn't generate any error messages, and can open and close the window an infinite number of times: 
    <script language="JavaScript"><!--
    var windowHandle = null;
    var windowHandle_closed = false;function openWindow() {
        windowHandle = window.open('http://www.irt.org/','windowName','height=200,width=200');
        if (windowHandle_closed) {
            windowHandle_closed = false;
        }
    }function closeWindow() {
        if (windowHandle != null) {
            if (!windowHandle_closed) {
                windowHandle_closed = true;
                windowHandle.close();
            }
        }
    }
    //--></script> 
      

  4.   

    问题就此打住
    我已经知道问题出在哪里了
    我和你的程序都没错
    上面的文章说的也没错
    搞了几天
    原来大家都没错
    错的是我自己用vb写的测试程序
    他引用的是ie以前的版本
    怪不得我按上面的文章去写一直出错
    谢谢你的帮忙我的e是 [email protected]
    有空联络 
      

  5.   

    skyyoung(路人甲)
    再次谢谢你进来帮忙