I am working on online examination system using php and mysql and I am new to this programing language. I want to prevent the one taking the exam from leaving the questions page by clicking on the back button or accidentally closing the tab. I want to warn the user that all his work will be lost if he leaves the page and if he decides to leave then he/she will get zero marks on the exam.
I have found many people providing solutions to this problem but none of them worked with me, so,it would be nice if any one can help with a simple code that can do what I need using javascript