56

更新ボタンがクリックされたか、ブラウザの戻るボタンがクリックされたかをFirefoxで知る方法...両方のイベントonbeforeunload()メソッドはコールバックです。IE の場合、次のように処理しています。

function CallbackFunction(event) {
    if (window.event) {
        if (window.event.clientX < 40 && window.event.clientY < 0) {
            alert("back button is clicked");
        }else{
            alert("refresh button is clicked");
        }
    }else{
        // want some condition here so that I can differentiate between
        // whether refresh button is clicked or back button is clicked.
    }
}

<body onbeforeunload="CallbackFunction();"> 

しかし、Firefox ではevent.clientXevent.clientY は常に 0 です。それを見つける他の方法はありますか?

4

4 に答える 4

7

jquery の戻るボタンの場合 // http://code.jquery.com/jquery-latest.js

 jQuery(window).bind("unload", function() { //

そしてhtml5にはイベントがあり、イベント は「popstate」と呼ばれます

window.onpopstate = function(event) {
alert("location: " + document.location + ", state: " + JSON.stringify(event.state));
};

更新について は、Javascript でページが再読み込みまたは更新されたかどうかを確認してください。

Mozilla Client-x では、client-y はドキュメント エリア内にあり ます https://developer.mozilla.org/en-US/docs/Web/API/event.clientX

于 2013-08-29T11:53:16.727 に答える
-8
var keyCode = evt.keyCode;
if (keyCode==8)
alert('you pressed backspace');

if(keyCode==116)
alert('you pressed f5 to reload page')
于 2013-09-05T05:25:56.610 に答える