0

I have a 3 pages from 1st page to second and second to third im sending some information.what i wanted to do is if im in the second page i want user to not to go back to 1st page again or in 3rd place users can go to 1st or 2nd page.

Is there is a way to disable back button on browser?or is there is a way to show an error when user press back button?

Any suggestions?

3
  • It's already available in stackoverflow : stackoverflow.com/questions/12381563/… Commented Nov 25, 2015 at 4:12
  • From the sudipta's link check this answer :stackoverflow.com/a/20321530/2630817 this is what you need Commented Nov 25, 2015 at 4:15
  • Can you explain why you don't want someone to go back? Is this for some sort of shopping cart or similar workflow? Commented Nov 25, 2015 at 22:22

3 Answers 3

1

This is my old code for that inside my Master Page It's been a couple of years since I made this, your choice if you want to update it.

    Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
       MyBase.OnPreRender(e)
       Dim disAbleBackButton As String
       disAbleBackButton = "<script language='javascript'>" & Environment.NewLine
       disAbleBackButton &= "function noBack(){window.history.forward()}" & Environment.NewLine
       disAbleBackButton &= "noBack();" & Environment.NewLine
       disAbleBackButton &= "window.onload=noBack;" & Environment.NewLine
       disAbleBackButton &= "window.onpageshow=function(evt){if(evt.persisted)noBack()}" & Environment.NewLine
       disAbleBackButton &= "window.onunload=function(){void(0)}" & Environment.NewLine
       disAbleBackButton &= "</script>"
       Page.ClientScript.RegisterClientScriptBlock(Me.Page.GetType(), "backhistory", disAbleBackButton)
  End Sub
Sign up to request clarification or add additional context in comments.

Comments

0

Try below code for disable browser back button using javascript.

<script type="text/javascript" language="javascript">
function DisableBackButton() {
  window.history.forward()
}
DisableBackButton();
window.onload = DisableBackButton;
window.onpageshow = function(evt) { if (evt.persisted) DisableBackButton() }
window.onunload = function() { void (0) }
</script>

Comments

0

Try below code to block back & forward buttons on the browser.

window.history.pushState(null, "", window.location.href);  
window.history.back();
window.history.forward();      
window.onpopstate = function() {
    window.history.pushState(null, "", window.location.href);
};

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.