代码之家  ›  专栏  ›  技术社区  ›  Greg Domjan

如何保证一个已命名的弹出窗口被关闭,从而可以创建一个同名的新窗口?

  •  0
  • Greg Domjan  · 技术社区  · 14 年前

    Using Internet Explorer (don't appear to have an issue in FireFox) the following code will occassionally raise an

    Error: Access is denied. 
    Code: 0
    

    有问题的行是第二个window.open。

    currentDialog = window.open("error.html", name, "width=20 height=20 left=50 top=70", true);
    if (currentDialog != null)
      currentDialog.close();
    
    currentDialog = window.open("about:blank", name, "width=20 height=20 left=50 top=70", true);
    

    However if a delay is introduced - not sure how long is really necessary or about consistency - then the first window opens and closes and the second window will open successfully.

    currentDialog = window.open("error.html", name, "width=20 height=20 left=50 top=70", true);
    if (currentDialog != null)
      currentDialog.close();
    
    //Small delay to allow slow addons enough time to process OnLoad/OnQuit() 
    var date = new Date(); 
    var curDate = null; 
    
    do { curDate = new Date(); } 
    while(curDate-date < 300); 
    
    currentDialog = window.open("about:blank", name, "width=20 height=20 left=50 top=70", true);
    

    不高兴有一些随机的时间长度。

    currentDialog.close(); 在正确处理之前不会返回,以便可以在如上所示的相同函数中成功创建具有相同名称的新窗口?

    背景

    The window is used for displaying a special selection dialog which should be modal. To get modal when the window is created onfocus and onunload events are added so that if the focus changes to the main page the focus is set back to the selection dialog and if the main page is closed then the modal dialog is closed.

    当快速通过选择器时,有时会在尝试挂接第二个对话框后取消第一个对话框的挂接,因此对话框没有适当的模式操作。

    也许更好的解决办法是: 是否有其他方法来获取此模式对话框操作并避免“创建”中间错误页?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Greg Domjan    14 年前

    while(!currentDialog.closed);