2

アプリケーションのようなメール用に新しいブラウザウィンドウ(ポップアップウィンドウ)を開くjqueryスクリプトを作成しようとしています(ユーザーはメールをダブルクリックすると、新しいウィンドウで開きます)。

それは特に難しいことではありません。私の問題は、開いているウィンドウを追跡したいので、ユーザーが同じメールアイテムをもう一度ダブルクリックすると、すでに開いているポップアップウィンドウにフォーカスが設定され、リロードされないようにすることです。

Firefoxで動作していますが、InternetExplorerは次のエラーを返します。

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のものであり、少なくともWindows7ベータ版のバージョンであることが判明しました。テストページ(http://egil.dk/popuptest/popup-source.htm)を作成しましたが、同僚のIE7からは期待どおりに機能しているようです。ああ、時間の無駄だ!

更新2:おそらくエラーを再現する方法を教えてください。http://egil.dk/popuptest/popup-source.htmにアクセスし、リンクの1つ、つまり「something 1」をクリックします。ポップアップの読み込みが完了したら、タブで親ウィンドウに戻り、同じリンクをクリックします。また。今回は、ポップアップウィンドウが再びフォーカスを受け取り、リロードしません(これは意図的であり、私が望むものです)。ポップアップウィンドウを閉じてから、同じリンクをもう一度クリックします。これにより、IE8ベータ版でエラーが発生します。Firefoxでは正しく再起動します。

4

3 に答える 3

4

私が気付いた唯一のことは、デフォルトのメニューバーの後に余分なコンマがあることです。その最後のコンマを削除した後、IE7では問題なく動作しました。IEがこの問題を引き起こしている場合、どのバージョンですか?

于 2009-02-03T19:51:42.047 に答える
1

以下は私のために働いているようです。改善できる人いたらお願いします!

Firefox では、ポップアップが開いている場合にのみフォーカスされます。IE8 では、「インターフェイスが不明です」というエラーがキャッチされ、ポップアップが閉じられ、代わりに再度開かれます。いずれの場合も、window.open 行は現在の「ページ」をポップアップにロードします。

var bigimg; // この変数を関数の外で設定するので、初めて
             // ポップアップが開きます。bigimg は定義済みの変数であり、if はチョークしません。

関数 popupbigpic(ページ)
  {
  試す
    {
    if(window.focus && bigimg) bigimg.focus();
    }
  キャッチ(エラー)
    {
    if(bigimg) bigimg.close();
    }
  bigimg = window.open(page,"popup","width=670,height=665,toolbar=no");
  }
于 2010-08-26T17:10:02.103 に答える