jquery/javascript ポップアップ ウィンドウ スクリプトに関するヘルプが必要 - Internet Explorer で奇妙なエラーが発生する

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

質問

メールのようなアプリケーションの新しいブラウザウィンドウ(ポップアップウィンドウ)を開く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 つをクリックします。つまり、「something 1」、ポップアップの読み込みが完了したら、Tab キーで親ウィンドウに戻り、同じリンクをもう一度クリックします。今回は、ポップアップ ウィンドウは再びフォーカスを受け取るだけで、リロードはしません (これは意図的であり、私が望んでいることです)。次に、ポップアップ ウィンドウを閉じて、同じリンクをもう一度クリックします。これにより、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が機能しないという問題が発生しました。ウィンドウ名をnullに置き換えただけです。 http://msdn.microsoft.com/en-us/library/ms536651.aspx

window.open( "sample.htm"、null、 "height = 200、width = 400、status = yes、toolbar = no、ne、no、no、location = no");

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top