0

I have to prevent browser back button.

for example I have two page((using xml & xslt))

  1. Login.aspx
  2. Page1.aspx

1 .while loading Login page I have created one guid and stored in Login.aspx hidden variable

  1. while loading Page1.aspx I have Created another guid and stored in page1.aspx hidden variable

when user clicks browser back button I an sending hidden variable from page1.aspx to Login.aspx while loading here i need check guids to confirm it is from page1.aspx and redirect to same page.

// I have to prevent browser back button(any suggestion is appreciated)

Praveen
  • 1
  • 1
  • Hope [this](https://stackoverflow.com/questions/25806608/how-to-detect-browser-back-button-event-cross-browser) helps you – FortyTwo Feb 14 '23 at 14:57
  • Please provide enough code so others can better understand or reproduce the problem. – Community Feb 14 '23 at 22:08

1 Answers1

0

This works for me on my asp.net website.

In the login.aspx html, add "onload="window.history.forward();" to the body statement:

<body onload="window.history.forward();">

Note: This only kicks in after the user interacts with Page1.aspx. It will send you user back to Page1.aspx if they use the previous page browser function on Page1.aspx.

  • I tried this but it is not working can suggest any other ways like page sequencing – Praveen Feb 15 '23 at 13:03
  • Interesting. I assume you added the code to Login.aspx? What browser are you using? Keep in mind that it does not work on the initial Page1.aspx load. So hitting the previous button when Page1 is first displayed will send it back to Login.aspx. Can you add your html to your guestion? –  Feb 15 '23 at 20:03
  • For security reasons modern browsers do not allow browser controls to be disabled. The solution I described just immediately sends the user back to Page1 from the Login page. I do not know how complex your website is. However, you could combine the login and Page1 functions in the same program. Putting the controls in panels allows you to easily hide the html that is not in use. To the user it would look like 2 pages. –  Feb 15 '23 at 20:17