jquery - how to get a callback refresh function after alert is displayed? -


i try make simple password function in jquery work need to. right now, on page load, prompted enter password see body of page. if password incorrect, alert wrong. works dead there.

what need button "try again" in alert refreshes page can try again. how do this? perhaps has solution work?

i cant use js fiddle type of task since wouldn't able see code if pass incorrect (therefore not seeing issue). so, must paste code here. hope ok.

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>-</title> </head> <body style="display:none;color: #000;"> <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>  <script type="text/javascript"> $( document ).ready(function() { var password var pass1="123" password=prompt('please enter password view page') if (password==123) { $('body').show(); } else{   alert('password incorrect! try again!') } }); </script>  page content password protected </body> </html> 

why need refresh page? use loop:

var correct_pass = false;  while (!correct_pass) {     var pass1 = '123';     var password = prompt('please enter password view page');      if (password == pass1) {         $('body').show();         correct_pass = true;     } else {         alert('password incorrect! try again!');     } } 

you expand function make little more capable, say, won't bug user 2 popups in row if type pass wrong:

(function get_password(prev_bad_pass = false) {     if (prev_bad_pass) {         var prompt_text = 'password incorrect! try again!';     } else {         var prompt_text = 'please enter password view page';     }      var pass1 = '123';     var password = prompt(prompt_text);      if (password == pass1) {         $('body').show();     } else {         get_password(true);   //run function again     } }()); 

this function execute on , on until correct password typed. can in fiddle: http://jsfiddle.net/v2fma/


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -