Hai bisogno di aiuto con jQuery / script javascript finestra a finestra - sempre strano errore in Internet Explorer

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

Domanda

Sto cercando di costruire uno script jQuery che si aprirà una nuova finestra del browser (finestra pop-up) per una posta come l'applicazione (l'utente può fare doppio clic su posta elettronica e si apre in una nuova finestra).

Non è difficile particolare. Il mio problema è che voglio tenere traccia delle finestre aperte, in modo che se fa doppio clic un utente sullo stesso elemento di posta un secondo tempo, sarà sufficiente impostare focus sulla finestra popup già aperta, e non ricaricarla.

L'ho lavorare in Firefox, ma Internet Explorer restituisce il seguente errore:

Line: 51
Error: The interface is unknown.

In particolare, accade quando gli utenti ha chiuso una finestra pop-up, e quindi fare doppio clic sulla voce di posta per aprire di nuovo.

I miei JavaScript / jQuery competenze sono rudimentali nella migliore delle ipotesi, quindi spero che qualcuno qui può dare una mano. Ecco il codice per lo 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);

La riga di codice che mi sta dando l'errore è:

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

Grazie, Egil.

UPDATE: scopre che questo è in realtà una cosa IE8, almeno la versione della beta di Windows 7. Ho messo su una pagina di prova ( http://egil.dk/popuptest/popup-source.htm ) e sembra funzionare come previsto in dai miei colleghi IE7. Gah, tempo sprecato!

UPDATE 2: forse dovrei dire come riprodurre l'errore. Vai a http://egil.dk/popuptest/popup-source.htm , clicca su uno dei link, vale a dire "qualcosa di 1", dopo la comparsa termine del caricamento, scheda di nuovo al di finestra padre, e fare clic sullo stesso collegamento di nuovo. Questa volta, la finestra pop-up sarà solo ricevere l'attivazione di nuovo, e non ricaricare (questo è intenzionalmente e quello che voglio). Ora chiudete la finestra pop-up, quindi fare clic sullo stesso collegamento di nuovo. Questo produce l'errore nella beta di IE8. In Firefox si riapre in modo corretto.

È stato utile?

Soluzione

L'unica cosa che ho notato è che si dispone di una virgola in più dopo barra dei menu nelle impostazioni predefinite. Dopo aver rimosso quella ultima virgola ha funzionato bene per me su IE7. Quale versione di IE, se ti dà questo problema?

Altri suggerimenti

Di seguito sembra funzionare per me. Se qualcuno può migliorare questo servizio, si prega di fare!

In Firefox, il pop-up ottiene solo concentrarsi se è aperto. In IE8, il "interfaccia è sconosciuto" errore viene catturato e il popup viene chiuso e riaperto, invece. In tutti i casi, la linea window.open carica la 'pagina' corrente nel 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");
  }

ho avuto problema con IE 8 che window.open non funzionava, ho solo sostituito il nome della finestra con null, ho avuto un'idea da http://msdn.microsoft.com/en-us/library/ms536651.aspx

window.open ( "campione.htm", null,     "Height = 200, width = 400, status = yes, toolbar = no, menubar = no, location = no");

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top