質問

がありうる場合、ユーザーを閉じるタブをwebブラウザです。具体的にはIE7、FireFoxやめのうを加工して作られます。う扱うことができることから、当社によるaspコードの場合は現在のタブを含む当社のウェブサイトが閉じます。

役に立ちましたか?

解決

" onbeforeunload &quotを添付する;イベント。ブラウザ/タブが閉じる直前にコードを実行できます。

他のヒント

onbeforeunloadは、次のイベントでも呼び出されます-

* Close the current browser window.
* Navigate to another location by entering a new address or selecting a Favorite.
* Click the Back, Forward, Refresh, or Home button.
* Click an anchor that refers the browser to another Web page.
* Invoke the anchor.click method.
* Invoke the document.write method.
* Invoke the document.open method.
* Invoke the document.close method.
* Invoke the window.close method.
* Invoke the window.open method, providing the possible value _self for the window name.
* Invoke the window.navigate or NavigateAndFind method.
* Invoke the location.replace method.
* Invoke the location.reload method.
* Specify a new value for the location.href property.
* Submit a form to the address specified in the ACTION attribute via the INPUT type=submit control, or invoke the form.submit method.

したがって、ユーザーがタブまたはブラウザーウィンドウを閉じた場合にユーザーをログアウトしようとすると、ユーザーがリンクをクリックするかページを送信するたびにログアウトすることになります。

document.unloadはあなたがそうしないのですか?

ページがサーバー側でいつ閉じられるかを知る必要がある場合、最善の策はページからサーバーに定期的にpingを実行することです(たとえば、 XMLHttpRequest を使用)。 pingが停止すると、ページは閉じられます。これは、ブラウザーがクラッシュした場合、終了した場合、またはコンピューターの電源が切れた場合にも機能します。

Eran Galperinが示唆したように、 onbeforeunload を使用します。特に、文字列を返すと、その文字列は確認ダイアログに含まれ、ユーザーはページを離れるかどうかを選択できます。各ブラウザには、返される文字列の前後にテキストが含まれているため、異なるブラウザでテストして、ユーザーに表示される内容を確認する必要があります。

いっOPたしていることをご確認いただこのにコンテキストからのウェブページそのものはもちろん、Firefox-アドオン開発者の方々にこの問題に利用できます TabClose イベントです。 https://developer.mozilla.org/en/Code_snippets/Tabbed_browser#Notification_when_a_tab_is_added_or_removed

Santoshは正しいです。このイベントは、タブ/ブラウザの閉じるボタンをクリックするだけでなく、多くのアクションでトリガーされます。次の関数をドキュメントの準備完了に追加することでonbeforeunloadアクションがトリガーされるのを防ぐために、ちょっとしたハックを作成しました。

       $(function () {     
        window.onbeforeunload = OnBeforeUnload;
            $(window).data('beforeunload', window.onbeforeunload);
            $('body').delegate('a', 'hover', function (event) {
                if (event.type === 'mouseenter' || event.type === "mouseover")
                    window.onbeforeunload = null;
                else
                    window.onbeforeunload = $(window).data('beforeunload');
            });
        });

また、Santoshが言及したイベントをトリガーする前に、次の行を実行する必要があります。

window.onbeforeunload = null;

イベントをトリガーしたくない場合。

最後のコードは次のとおりです。

    function OnBeforeUnload(oEvent) {   
            // return a string to show the warning message (not every browser will use this string in the dialog)
            // or run the code you need when the user closes your page  
        return "Are you sure you want to close this window?";       
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top