1

I have this script for detecting if browser back button pressed. which I got from http://www.bajb.net/2010/02/browser-back-button-detection/.

var bajb_backdetect={Version:'1.0.0',Description:'Back Button Detection',Browser:{IE:!!(window.attachEvent&&!window.opera),Safari:navigator.userAgent.indexOf('Apple')>-1,Opera:!!window.opera},FrameLoaded:0,FrameTry:0,FrameTimeout:null,OnBack:function(){alert('Back Button Clicked')},BAJBFrame:function(){var BAJBOnBack=document.getElementById('BAJBOnBack');if(bajb_backdetect.FrameLoaded>1){if(bajb_backdetect.FrameLoaded==2){bajb_backdetect.OnBack();history.back()}}bajb_backdetect.FrameLoaded++;if(bajb_backdetect.FrameLoaded==1){if(bajb_backdetect.Browser.IE){bajb_backdetect.SetupFrames()}else{bajb_backdetect.FrameTimeout=setTimeout("bajb_backdetect.SetupFrames();",700)}}},SetupFrames:function(){clearTimeout(bajb_backdetect.FrameTimeout);var BBiFrame=document.getElementById('BAJBOnBack');var checkVar=BBiFrame.src.substr(-11,11);if(bajb_backdetect.FrameLoaded==1&&checkVar!="HistoryLoad"){BBiFrame.src="blank.html?HistoryLoad"}else{if(bajb_backdetect.FrameTry<2&&checkVar!="HistoryLoad"){bajb_backdetect.FrameTry++;bajb_backdetect.FrameTimeout=setTimeout("bajb_backdetect.SetupFrames();",700)}}},SafariHash:'false',Safari:function(){if(bajb_backdetect.SafariHash=='false'){if(window.location.hash=='#b'){bajb_backdetect.SafariHash='true'}else{window.location.hash='#b'}setTimeout("bajb_backdetect.Safari();",100)}else if(bajb_backdetect.SafariHash=='true'){if(window.location.hash==''){bajb_backdetect.SafariHash='back';bajb_backdetect.OnBack();history.back()}else{setTimeout("bajb_backdetect.Safari();",100)}}},Initialise:function(){if(bajb_backdetect.Browser.Safari){setTimeout("bajb_backdetect.Safari();",600)}else{document.write('<iframe src="blank.html" style="display:none;" id="BAJBOnBack" onunload="alert(\'de\')" onload="bajb_backdetect.BAJBFrame();"></iframe>')}}};bajb_backdetect.Initialise();

For that I have to include following 3-4 line in my jsp from which I want to detect it.

<script type="text/javascript" src="backfix.min.js"></script>
<script type="text/javascript">
    bajb_backdetect.OnBack = function()
    {
        //alert('You clicked it!');
        logoutUser();

    }

      /*window.history.forward();    
      function noBack() { 
      window.history.forward(); 
      }*/


</script>

Using this script by detecting if user has pressed back button ,I want to invalidate session of user page contains vital processing.

Which is working fine in only Firefox Mozilla browser. but in rest other browsers like IE,Google chrome,safari,torch this script fails to run.

please help me out

yatinbc
  • 515
  • 3
  • 13
  • 32
  • These links might help: 1) [Disable back button](http://viralpatel.net/blogs/disable-back-button-browser-javascript/) 2) [Controlling back button](http://stackoverflow.com/questions/910840/how-to-control-over-browser-back-button) 3) [Track when user hits back-button](http://stackoverflow.com/questions/55871/track-when-user-hits-back-button-on-the-browser) 4) [alternative to controlling browser button in JSP](http://www.coderanch.com/t/283574/JSP/java/controlling-browsers-button) 5) [Java way to prevent user from going back](http://stackoverflow.com/q/4194207/468763) – Prakash K Mar 08 '13 at 07:19

0 Answers0