Precisa de ajuda com roteiro janela jquery / pop-up javascript - recebendo erro estranho no internet explorer

StackOverflow https://stackoverflow.com/questions/507968

Pergunta

Eu estou tentando construir um script jQuery que irá abrir uma nova janela do navegador (janela pop-up) para um mail como o aplicativo (o usuário pode clicar duas vezes sobre mails e eles vão abrir em uma nova janela).

Isso não é particularmente difícil. Meu problema é que eu quero acompanhar as janelas abertas, de modo que se um usuário clicar duas vezes sobre o mesmo item de correio uma segunda vez, ela só vai definir o foco na janela pop-up já está aberto, e não recarregá-lo.

Eu tenho que trabalhar no Firefox, mas o Internet Explorer retorna o seguinte erro:

Line: 51
Error: The interface is unknown.

Em particular, isso acontece quando os usuários fechou uma janela pop-up e, em seguida, clique duas vezes no item de correio para abri-lo novamente.

As minhas habilidades javascript / jQuery são rudimentares na melhor das hipóteses, então eu espero que alguém aqui pode ajudar. Aqui está o código para o script.

(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);

A linha de código que está me dando o erro é:

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

Obrigado, Egil.

UPDATE: Acontece que este é de fato uma coisa IE8, pelo menos a versão do Windows 7 beta. Eu coloquei uma página de teste ( http://egil.dk/popuptest/popup-source.htm ) e parece funcionar como esperado na dos meus colegas IE7. Gah, tempo perdido!

UPDATE 2: eu provavelmente deveria dizer como reproduzir o erro. Vá para http://egil.dk/popuptest/popup-source.htm , clique em um dos links, ou seja, "algo 1", após a pop-up terminar o carregamento, guia de volta para a janela pai, e clique sobre o mesmo link novamente. Desta vez, a janela pop-up irá apenas receber foco novamente e não recarregar (isto é intencional e que eu quero). Agora feche a janela de pop-up e clique no mesmo link novamente. Isso produz o erro no IE8 beta. No Firefox corretamente reabre.

Foi útil?

Solução

A única coisa que eu reparei é que você tem uma vírgula extra após menu em seus padrões. Depois de retirar a última vírgula funcionou muito bem para mim no IE7. Qual versão se IE está lhe dando este problema?

Outras dicas

A seguir parece estar a trabalhar para mim. Se qualquer um pode melhorá-lo, por favor!

No Firefox, o pop-up só fica foco se ele estiver aberto. No IE8, a "interface é desconhecida" erro é capturado e o popup é fechado e reaberto em seu lugar. Em todos os casos, as cargas de linha window.open a 'página' atual para o pop-up.

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");
  }

Eu tive problema com o IE 8 que window.open não estava funcionando, eu só substituiu o nome da janela com nulo, eu tenho ideia de http://msdn.microsoft.com/en-us/library/ms536651.aspx

window.open ( "Sample.htm", null, "Height = 200, width = 400, status = yes, toolbar = no, menubar = no, local = não");

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top