Click here to Skip to main content
15,117,549 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need disable the browser back button after the window alert.
in page1.aspx i put like this

 
After in Page2.aspx

 I put alert message when button click.once close the alert message i press the back button.
 same alert show when each click of back button.
(How to prevent the alert message when back button press)


What I have tried:

**$(document).ready(function () {
             function disableBack() { window.history.forward() }
             window.onload = disableBack();
             window.onpageshow = function (evt) { if (evt.persisted) disableBack() }
         });**
Posted
Updated 12-Mar-19 20:47pm
Comments
Madhukar Krishna 12-Mar-19 1:52am
   
Try this

function preventBack() { window.history.forward(); }
setTimeout("preventBack()", 0);
window.onunload = function () { null };

1 solution

You cannot disable the Browser button, however you can prevent it to use.

Following code may help you -

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900