How to disable back button using JS

Method 1:

<!-- Script by hscripts.com -->
<script type="text/javascript">
	window.history.forward(1);
	function noBack()
  { 
  window.history.forward(); 
  }
</script>
<!-- Script by hscripts.com -->
<!-- Script by hscripts.com -->
 <body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
  <center>  <a href="test.php"><H2>HIOX</H2></a>
    <p><b>When ever you have to be click <b>HIOX</b>,the back button will be disabled.</b>
    </p>
  </center>
  </body>
	<div style="font-size: 10px;color: #dadada;" id="dumdiv" align=center>
<a href="http://www.hscripts.com" id="dum" style="text-decoration:none;color: #dadada;">©h</a></div>


Method 2:

Following is the code to open webpage in a new window have no toolbar (Back/Next buttons).

window.open ("http://viralpatel.net/blogs/",
"mywindow","status=1,toolbar=0");

Also it is possible to disable the right click on any webpage using Javascript. Add following code in the webpage.

 <body oncontextmenu="return false;">

This is another technique to disable the back functionality in any webpage. We can disable the back navigation by adding following code in the webpage. Now the catch 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 user follows the navigation page1 -> page2. And you want to stop user from page2 to go back to page1. In this case all following code in page1.

<SCRIPT type="text/javascript">
    window.history.forward();
    function noBack() { window.history.forward(); }
</SCRIPT>
</HEAD>
<BODY onload="noBack();"
    onpageshow="if (event.persisted) noBack();" onunload="">
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s