javascript
  • php
  • 2016-05-30 54 views 0 likes 
    0

    如果按F5鍵,我想啓用Google reCAPTCHA。 我有此代碼的那一刻:Google reCAPTCHA(如果按F5鍵)

    <html> 
     
    <head> 
     
    <title>HELLO</title> 
     
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
     
    <script src='https://www.google.com/recaptcha/api.js'></script> 
     
    <script type="text/javascript"> 
     
    document.onkeydown = fkey; 
     
    document.onkeypress = fkey 
     
    document.onkeyup = fkey; 
     
    
     
    var wasPressed = false; 
     
    
     
    function fkey(e){ 
     
         e = e || window.event; 
     
         if(wasPressed) return; 
     
    
     
         if (e.keyCode == 116) { 
     
          alert("f5 pressed"); 
     
          // here the Google reCAPTCHA code have to come. 
     
          wasPressed = true; 
     
         }else { 
     
          alert("Window closed"); 
     
         } 
     
    } 
     
    </script> 
     
    </head> 
     
    <body> 
     
    <p>If you press F5 you will get a Google reCAPTCHA</p> 
     
    </body> 
     
    </html>

    <div class="g-recaptcha" data-sitekey="6LehRSETAAAAAIl2C3nRFguErdFn02smPN_vtPro"></div> 
    

    這是展示了谷歌驗證碼的代碼。

    我希望有人能幫助我,所以我可以走得更遠。謝謝:d

    回答

    0

    <html> 
     
    <head> 
     
    <title>HELLO</title> 
     
    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
     
    <script src='https://www.google.com/recaptcha/api.js'></script> 
     
    <script type="text/javascript"> 
     
    document.onkeydown = fkey; 
     
    document.onkeypress = fkey 
     
    document.onkeyup = fkey; 
     
    
     
    var wasPressed = false; 
     
    
     
    function fkey(e){ 
     
         e = e || window.event; 
     
         if(wasPressed) return; 
     
    
     
         if (e.keyCode == 116) { 
     
          // here the Google reCAPTCHA code have to come. 
     
          $('.g-recaptcha').show(); 
     
          e.preventDefault(); 
     
          wasPressed = true; 
     
         }else { 
     
          alert("Window closed"); 
     
         } 
     
    } 
     
    </script> 
     
    </head> 
     
    <body> 
     
    <p>If you press F5 you will get a Google reCAPTCHA</p> 
     
    <div class="g-recaptcha" data-sitekey="6LehRSETAAAAAIl2C3nRFguErdFn02smPN_vtPro" style="display:none;"></div> 
     
    </body> 
     
    </html>

    +0

    我已經加入了e.preventDefault(),以阻止刷新瀏覽器。您可以根據需要修改上述內容。 – Siddharth

    相關問題