user1789716
user1789716

Reputation: 55

Which solution is best when the browser back button is hit

I have an application and the problem I have is with the back brower buttons, if the user cliks on a back browser, then it would mess things up in the application.

So I want to do either 2 things:

Solution 1: I have found a site where it shows the javascript code for disabling back buttons on all browsers. Obviously you need javascript enabled for this to work but my application won't work very well without javascript anyway so this won't be a problem (I include a warning in each page in my application stating javascript must be enabled in order to use the app)

Solution 2: IF the user does click on the back button at any time, then it will navigate the user to the safety.php page where on this page it will inform the user that they can't use the browser back button, then it will destroy all of the sessions so that the user is logged out. If they want to use the app again then they will have to login again and use the app from the beginning.

My question is that out of both solutions, which one would be better to use? My application is where a teacher creates an online assessment, creating the assessments detials (start time/ duration date etc) and creating the questions and answers for each assesment (could be single or multiple assessments)

Upvotes: 3

Views: 1084

Answers (2)

alfred
alfred

Reputation: 1018

use javascript in the first place to prevent adding the location to the history list. catch the onclick event of the proper link, and use document.location.replace("next_page.html"); so this way, when a user clicks the back button he would leave your site, rather then going back and messing up your app.

also: you can catch the unload event of the page where the user presses back button, so that you can confirm the user for exiting.

Upvotes: 0

Randy Hall
Randy Hall

Reputation: 8167

Disabling the back button is generally poor usability practice. Your best bet is to manipulate the history object (search pushState if you're not familiar with these methods) so that hitting the back button would return them to a page outside your experience, or however you're accomplishing "Solution 2", but warn them that they are leaving the "logged in" section before they actually leave the page, so that they can choose to stay, using confirm() or a custom pop-up.

Upvotes: 1

Related Questions