我试图建立一个jquery脚本,将打开一个新的浏览器窗口(弹出窗口)的邮件如应用(用户可以双击邮件,他们将在新窗口中打开)。

这是不特别硬。我的问题是,我要跟踪打开的窗口,因此,如果在同一个邮件项目的用户双击第二次,它只会设置已经打开弹出窗口焦点,而不是重新加载它。

我已经在Firefox的工作,但Internet Explorer中返回以下错误:

Line: 51
Error: The interface is unknown.

在特别的,当它发生在用户已经关闭了一个弹出窗口,然后在邮件上双击该项目再次打开它。

我的JavaScript / jQuery的技能是基本的最好的,所以我希望有人在这里可以帮忙。下面是脚本的代码。

(function($)
{
    var _popupTracker = {}
    var _popupCounter = 0;
    $.fn.openPopupWindow = function(options)
    {
        var defaults = {
            height: 600, // sets the height in pixels of the window.
            width: 600, // sets the width in pixels of the window.
            toolbar: 0, // determines whether a toolbar (includes the forward and back buttons) is displayed {1 (YES) or 0 (NO)}.
            scrollbars: 0, // determines whether scrollbars appear on the window {1 (YES) or 0 (NO)}.
            status: 0, // whether a status line appears at the bottom of the window {1 (YES) or 0 (NO)}.
            resizable: 1, // whether the window can be resized {1 (YES) or 0 (NO)}. Can also be overloaded using resizable.
            left: 0, // left position when the window appears.
            top: 0, // top position when the window appears.
            center: 0, // should we center the window? {1 (YES) or 0 (NO)}. overrides top and left
            createnew: 0, // should we create a new window for each occurance {1 (YES) or 0 (NO)}.
            location: 0, // determines whether the address bar is displayed {1 (YES) or 0 (NO)}.
            menubar: 0 // determines whether the menu bar is displayed {1 (YES) or 0 (NO)}.
        };

        var options = $.extend(defaults, options);

        var obj = this;

        // center the window
        if (options.center == 1)
        {
            options.top = (screen.height - (options.height + 110)) / 2;
            options.left = (screen.width - options.width) / 2;
        }

        var parameters = "location=" + options.location +
                         ",menubar=" + options.menubar +
                         ",height=" + options.height +
                         ",width=" + options.width +
                         ",toolbar=" + options.toolbar +
                         ",scrollbars=" + options.scrollbars +
                         ",status=" + options.status +
                         ",resizable=" + options.resizable +
                         ",left=" + options.left +
                         ",screenX=" + options.left +
                         ",top=" + options.top +
                         ",screenY=" + options.top;

        // target url
        var target = obj.attr("href");       

        // test if popup window is already open, if it is, just give it fokus.        
        var popup = _popupTracker[target];
        if (options.createnew == 0 && popup !== undefined && !popup.closed)
        {            
            popup.focus();
        } 
        else
        {
            var name = "PopupWindow" + _popupCounter;
            _popupCounter++;

            // open window
            popup = window.open(target, name, parameters);            
            _popupTracker[target] = popup;
            _popupTracker[target].focus();
        }

        return false;
    };        
})(jQuery);

的代码,是给我错误的行是:

if (options.createnew == 0 && popup !== undefined && !popup.closed)

谢谢,埃吉尔。

<强>更新原来,这实际上是一个IE8东西,至少在Windows 7测试的版本。我提出了一个测试页面( http://egil.dk/popuptest/popup-source.htm ),它似乎从我的同事IE7预期工作。尔加,浪费时间!

更新2:我也许应该告诉如何重现错误。转到 http://egil.dk/popuptest/popup-source.htm ,点击其中一个链接,即“事1”,在弹出完成加载,标签后返回给父窗口,然后再次单击同一链路上。这一次,弹出窗口将只再次收到焦点,而不会重新加载(这是故意和我想要的)。现在关闭弹出窗口,然后再次单击同一链路上。这将产生在IE8正式版的错误。在Firefox它正确地重新打开。

有帮助吗?

解决方案

这是我发现的唯一的事情是,你在你的默认菜单栏后,有一个额外的逗号。除去最后一个逗号之后,它工作得很好,我对IE7。哪个版本的IE浏览器,如果是给你这个问题?

其他提示

下面似乎是为我工作。如果任何人都可以改善它,请不要!

在Firefox中,弹出刚刚获得焦点,如果它是开放的。在IE8中,“接口是未知”被捕获错误,并弹出窗口关闭并重新打开来代替。在所有情况下,window.open行加载当前“页”到弹出。

var bigimg;  // set this variable outside the function so the first time 
             // the popup opens, bigimg is a defined variable and the if's don't choke.

function popupbigpic(page) 
  {
  try
    {
    if(window.focus && bigimg) bigimg.focus(); 
    }
  catch(err)
    {
    if(bigimg) bigimg.close();
    }
  bigimg = window.open(page,"popup","width=670,height=665,toolbar=no");
  }

我有问题与IE 8是window.open不工作,我只是空替换窗口名称,我接到的 http://msdn.microsoft.com/en-us/library/ms536651.aspx

window.open( “Sample.htm”,NULL,     “高度= 200,宽度= 400,状态=是,工具栏=没有,菜单栏=没有,位置=无”);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top