Warn User if Back is Pressed

Preventing users from going back using the back button is something that gets asked every now and again.

So if you want to warn a user if the “back button” is pressed then you can use the following javascript snippet:-

window.onbeforeunload = function() { return "If you go back your work will be lost."; };

This will add a warning message which opens in the browser when the back button is pressed. The problem is that is can sometimes with certain browsers pop up when you do not want it to.