Wednesday, 4 June 2014

Disable Back Functionality In Php Using Javascript

Disable Back Functionality In Php Using Javascript

There is a smart technique to disable the back functionality in any webpage. We can disable the back navigation by adding following bit of code in the webpage. Now the problem  here is that you have to add this code in all the pages where you want to avoid user to get back from previous page. For example  a user makes the navigation from page1 to page2. And we want to stop  user from page2 to go back to page1. In this case add following code will be added  in php  page1.


<HEAD>
<SCRIPT type="text/javascript">

    window.history.forward();

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

</SCRIPT>

</HEAD>

<BODY onload="noBack();"
    onpageshow="if (event.persisted) noBack();" onunload="">



The above code will trigger history.forward event for page1. That is  if user presses Back button on page2, he will be sent to page1. But the history.forward code on page1 makes the user back to page2. Thus user will not be able to go back from page2 to page1.





No comments:

Post a Comment