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?

Kaushik Maheta
  • 1,741
  • 1
  • 18
  • 27
Jude Nanayakkara
  • 251
  • 1
  • 2
  • 6
  • It's already available in stackoverflow : http://stackoverflow.com/questions/12381563/how-to-stop-browser-back-button-using-javascript – Sudipta Kumar Maiti Nov 25 '15 at 04:12
  • From the sudipta's link check this answer :http://stackoverflow.com/a/20321530/2630817 this is what you need – Just code Nov 25 '15 at 04:15
  • Can you explain why you don't want someone to go back? Is this for some sort of shopping cart or similar workflow? – Darren S Nov 25 '15 at 22:22

3 Answers3

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
rjps12
  • 587
  • 6
  • 15
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>
Kaushik Maheta
  • 1,741
  • 1
  • 18
  • 27
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);
};
rsmdh
  • 128
  • 1
  • 2
  • 12