Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 24 May 2016

How to disable back button in browser using javascript

How to disable back button in browser using javascript


1) If you are using some Form-Submission page and want to don't allow the user to back their previous page, then you must use this script. 


* Browser will set the history each time you visited any page, even if you are using "Private Browsing", but the history is not shown in history bar(Because you can customise the setting for storing history in private browsing).
This script will set the time for storing histrory  is 'ZERO', logically you can't do anything in 'ZERO-TIME'.

 You just copy and paste this code before closing the <head> tag.  


    <script type = "text/javascript" >
   function preventBack(){window.history.forward();}
    setTimeout("preventBack()", 0);
    window.onunload=function(){null};
     </script>

This script will overwrite attempts to navigate back and forth with the state of the current page.

2) If you are not just using  Form-Submission page and want to don't allow the user to back their previous page, then you can use this script. 

Note* This script remove the extension of that particular page (eg. abc.php -> abc).

This script will overwrite attempts to navigate back and forth with the state of the current page.

    <script type = "text/javascript" >
history.pushState(null, null, document.title);
window.addEventListener('popstate', function () {
    history.pushState(null, null, document.title);

});
</script>

No comments:

Post a Comment