Pankaj Pawar

Pankaj Pawar

  • NA
  • 116
  • 10.5k

redirect to another page if page reloaded 2nd time

Dec 28 2018 1:27 PM
i have a Quiz webpage, that showing questions and time with timer control. now i want that,
if user click on browser reload button and try to reload webpage then he/she will be redirected to another page. 
 
code should be work only, if user try to reload.  Not when first time page loaded.
 
i tried this code
 
var reload = confirm("are you sure you want to leave? your progress will be lost");
if (reload) {
location.href = "http://stackoverflow.com"; // Redirect.
}
 
but this code. showing confirm box, very first time also, when page loaded. 
now i dont want to show this confirm box and redirect when first time web page loaded.
i want that. code should be work only, if user try to reload.  Not when first time page loaded.
 
or if there is a way to achieve this in server side coding.  asp.net C# 4.5 2017
Hope you Understand,
 
thanks for any help.
 
 
 

Answers (1)