Click here to Skip to main content
14,304,027 members
Rate this:
Please Sign up or sign in to vote.
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() }
Updated 12-Mar-19 19:47pm
Madhukar Krishna 12-Mar-19 1:52am
Try this

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

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

Following code may help you -

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

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100