jQuery/JavaScript 팝업 창 스크립트에 대한 도움이 필요합니다 - Internet Explorer에서 이상한 오류가 발생합니다.

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

문제

응용 프로그램과 같은 메일에 새 브라우저 창 (팝업 창)을 열 수있는 jQuery 스크립트를 작성하려고합니다 (사용자는 메일을 두 번 클릭하면 새 창에서 열립니다).

그것은 특별한 것이 아닙니다. 내 문제는 열린 Windows를 추적하고 싶다는 것입니다. 사용자가 동일한 메일 항목을 두 번 클릭하면 이미 열린 팝업 창에 초점을 맞추고 다시로드하지 않도록합니다.

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에서 예상대로 작동하는 것 같습니다. 가, 시간 낭비!

UPDATE 2: 아마도 오류를 재현하는 방법을 말해야 할 것입니다. 이동 http://egil.dk/popuptest/popup-source.htm, 팝업이로드를 완료 한 후 링크 중 하나 인 "Something 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에 문제가있었습니다. http://msdn.microsoft.com/en-us/library/ms536651.aspx

window.open ( "sample.htm", null, "height = 200, 너비 = 400, 상태 = 예, 도구 모음 = 아니오, 메뉴 바 = 아니오, 위치 = 아니오");

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top