¿Necesita ayuda con / javascript guión ventana emergente jQuery - conseguir el error raro en Internet Explorer

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

Pregunta

Estoy tratando de construir un script de jQuery que se abrirá una nueva ventana del navegador (ventana emergente) para un correo, como la aplicación (el usuario puede hacer doble clic en los correos y que se abrirá en una nueva ventana).

Esto no es particularmente difícil. Mi problema es que quiero hacer un seguimiento de las ventanas abiertas, de modo que si un usuario hace doble clic sobre el mismo elemento de correo por segunda vez, se acaba de establecer el foco en la ventana emergente ya abierta, y no vuelva a cargarlo.

Tengo que funcione en Firefox, Internet Explorer, pero devuelve el siguiente error:

Line: 51
Error: The interface is unknown.

En particular, esto sucede cuando los usuarios se ha cerrado una ventana emergente y haga doble clic en el elemento electrónico para abrirlo de nuevo.

El código JavaScript / jQuery habilidades son rudimentarios en el mejor, así que espero que alguien aquí puede ayudar. Aquí está el código para la secuencia de comandos.

(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 línea de código que me está dando el error es:

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

Gracias, Egil.

ACTUALIZACIÓN: Resulta que esto es de hecho una cosa IE8, al menos en la versión beta de Windows 7. Puse una página de prueba ( http://egil.dk/popuptest/popup-source.htm ) y parece que funciona como se esperaba a partir de mis colegas IE7. Gah, tiempo perdido!

Actualización 2: probablemente debería decirle cómo reproducir el error. Ir a http://egil.dk/popuptest/popup-source.htm , haga clic en uno de los enlaces, es decir, "algo 1", después de que el emergente termina de cargar, la ficha de nuevo a los padres a la ventana, y haga clic en el mismo enlace de nuevo. Esta vez, la ventana emergente se acaba de recibir el foco nuevo, y no vuelva a cargar (esto es intencional y lo que quiero). Ahora cierra la ventana emergente y, a continuación, haga clic en el mismo enlace de nuevo. Esto produce el error en la versión beta de IE8. En Firefox correctamente abre de nuevo.

¿Fue útil?

Solución

La única cosa que he notado es que usted tiene una coma adicional después de la barra de menú en sus valores por defecto. Después de retirar a la última coma funcionó bien para mí en IE7. ¿Qué versión de IE si le está dando este problema?

Otros consejos

El siguiente parece estar funcionando para mí. Si alguien puede mejorarla, por favor hacerlo!

En Firefox, la ventana emergente sólo se pone foco si está abierto. En Internet Explorer 8, la "interfaz es desconocida" es capturado error y la ventana emergente está cerrado y abierto de nuevo en su lugar. En todos los casos, la línea window.open carga la 'página' actual en la ventana emergente.

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

he tenido problema con IE 8 que window.open no estaba funcionando, Acabo de cambiar el nombre de la ventana con el nula, tengo idea de http://msdn.microsoft.com/en-us/library/ms536651.aspx

window.open ( "muestra.htm", null,     "Height = 200, width = 400, estado = yes, barra de herramientas = no, barra de menú = no, location = no");

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top