2016-05-03 13 views
0

Ich möchte das Ereignis auf der Rückseite oder Refresh-Taste des Browsers abfangen. Ich habe keine perfekte Lösung gefunden, die nur Back-Event erfasst und mit allen Browsern kompatibel ist. Bitte geben Sie eine Lösung an.Bestätigen Sie das Kontrollkästchen im Browser zurück Schaltfläche

Vielen Dank im Voraus.

+0

vergessen zu erwähnen, dass ich an Java –

+0

Java oder Javascript arbeite? – hexafraction

+0

Javascript. Was auch immer sein mag, wollen nur dieses Ereignis zu fangen –

Antwort

0
window.userInteractionTimeout = null; 
window.userInteractionInHTMLArea = false; 
window.onBrowserHistoryButtonClicked = null; // This will be your event handler for browser navigation buttons clicked 

$(document).ready(function() { 
    $(document).mousedown(function() { 
     clearTimeout(window.userInteractionTimeout); 
     window.userInteractionInHTMLArea = true; 
     window.userInteractionTimeout = setTimeout(function() { 
      window.userInteractionInHTMLArea = false; 
     }, 500); 
    }); 

    $(document).keydown(function() { 
     clearTimeout(window.userInteractionTimeout); 
     window.userInteractionInHTMLArea = true; 
     window.userInteractionTimeout = setTimeout(function() { 
      window.userInteractionInHTMLArea = false; 
     }, 500); 
    }); 

    if (window.history && window.history.pushState) { 
     $(window).on('popstate', function() { 
      if (!window.userInteractionInHTMLArea) { 
       //document.location.href = "logOff.htm"; 
       setTimeout(function(){ var answer = confirm("Are you Sure?? This will expire your session"); 
       if(answer == true) 
        { 
        document.location.href = "logOff.htm"; 
        } 
       },100); 


       //alert('Browser Back or Forward button was pressed.'); 
      } 
      if (window.onBrowserHistoryButtonClicked) { 

       window.onBrowserHistoryButtonClicked(); 
      } 
     }); 
    } 
}); 
+0

Eine andere Lösung gefunden. Als ihr alle für eure Unterstützung. –

0

können Sie den Event-Handler onpopstate von HTML5 Geschichte API verwenden, wie folgt aus:

$(document).ready(function() { 

if (window.history && window.history.pushState) { 

$(window).on('popstate', function() { 
    //confirmation box 
    confirm('Back button clicked!'); 
}); 
} 
}); 

Beachten Sie, dass Sie benötigen, um eine Seite haben, um wieder auf ...

+0

Ich habe diesen Code bereits ausprobiert. Es funktioniert nicht. –