弹出窗口工作不正常

Pop up window not working properly

本文关键字:不正常 工作 窗口      更新时间:2023-09-26

onclick函数无法正常工作,因为即使在我关闭它之后,它也会禁用父窗口上的所有链接。在关闭弹出窗口时,父页面链接不再工作。其他一切都很好。

我的代码是:-

             function MyPopUpWin(message) {
             var iMyWidth;
         var iMyHeight;
         //half the screen width minus half the new window width (plus 5 pixel borders).
           iMyWidth = (window.screen.width/2) - (75 + 10);
         //half the screen height minus half the new window height (plus title and status bars).
          iMyHeight = (window.screen.height/2) - (100 + 50);
         //Open the window.
 var generator = window.open();
document.onclick=function()   {
    try{
        generator.focus();
        return false
    }
    catch(e){}
}
generator.document.write('<html><head><title>Pop uP</title>');
generator.document.write('<p style="color:#C52B27;">');
generator.document.write(message);
generator.document.write('</p>');
generator.document.write('</head><body>');
 generator.document.write('<a href="javascript:self.close()"><img src="/img/save_orange.gif" border=0">  <'/a>');
generator.document.write('</body></html>');
generator.document.close();
 }

关闭窗口后,对它的引用不会丢失。。。并且CCD_ 1方法没有失败。。所以你try/catch没有做你想做的事。。

<a href="javascript:window.opener.document.onclick = null;self.close();">

在弹出窗口关闭后,您必须从document中删除onclick-事件处理程序。

编辑:

我不知道哪一个比Gaby的答案更好,但试试这个:

document.body.onfocus=function (){generator.focus();return false;}

然后在退出弹出窗口时使onfocus无效。

或者,当弹出窗口打开时,只需在父窗口上使用(部分?)透明的盖子div

第2版

或者甚至使用showModaDialog()作为弹出窗口,尽管此解决方案需要其他文件才能加载到模式对话框。