0

I am developing one project so in that I need if user try to refresh page using f5,ctrl+r then prompt will ask if you refresh page all your data will loss if click yes one more alert should get and if click cancel on this case also alert should get but I am not getting any alert if click on ok or cancel button in prompt box.

<script src="https://code.jquery.com/jquery-3.3.1.js"></script>

<script>
     $(window).on('beforeunload', function(){ 

  return  aa=confirm("are you sure want to refresh this page !");

  if(aa===true){
       alert('You will loose your data');
   }
   else{
       alert("Ok continue your work");
   }
  });
<script>
Anonymous
  • 1,074
  • 3
  • 13
  • 37
  • `return aa=confirm` should be `var aa=confirm` – freedomn-m Jul 27 '18 at 13:01
  • @freedomn-m after chnaged to like this I am not getting prompt box with message 'are you sure want to leave this page' – Anonymous Jul 27 '18 at 13:05
  • That's a whole different issue... here's a question from yesterday that covers your new issue (which is actually a duplicate of one from 2010) - https://stackoverflow.com/questions/51531287/alert-is-not-working-when-user-try-to-refresh-browser-page-using-f5-ctrl5-using/51531457#comment90034427_51531457 – freedomn-m Jul 27 '18 at 13:14
  • Oh wait - just spotted who created that question :) – freedomn-m Jul 27 '18 at 13:17
  • As the answer you've already been given shows, this was removed from browsers about **8 years ago** as it was being abused by spammers/advertisers/hackers/etc – freedomn-m Jul 27 '18 at 13:17
  • @freedomn-m so how to solve this issue still I am not getting prompt box – Anonymous Jul 27 '18 at 13:22
  • Probably better to read the full answer that the one you accepted was copied from: https://stackoverflow.com/a/38880926/2181514 – freedomn-m Jul 27 '18 at 13:24

0 Answers0