2014-02-13 62 views
0

使用的Recaptcha的默認方式後投入:負載的Recaptcha一切裝完

<script src="http://www.google.com/recaptcha/api/challenge?k=publickey"></script> 

您想要的ReCaptcha出現。但是,我希望它出現在頁面中間,但我不希望它阻止頁面的其餘部分。

如何最後加載Recaptcha?

我有jQuery加載。

回答

1

發現這個代碼是在JQuery中。當文檔準備就緒時,這意味着頁面已完全加載。

// WHEN THE DOM HAS LOADED FIRE THE reCapInsert FUNCTION TO INSERT THE reCAPTCHA 
$(document).ready(function(){ 
    reCapInsert(); 
}); 

// WHEN CALLED THIS INSERTS THE reCAPTCHA INTO THE PAGE 
function reCapInsert(){ 
    Recaptcha.create('YOUR_PUBLIC_KEY_HERE', // public key 
    'recap', 
     { 
      theme: 'clean', 
      callback: Recaptcha.focus_response_field 
     } 
); 
} 

所有你真的在你的HTML頁面中放置這個代碼,它會在那個位置產生一個ReCaptcha。 (不要忘記在頁面的頁眉的ReCaptcha的JavaScript。)

<!-- The reCAPTCHA wrapper is here - this is required!! --> 
    <div id="recap"></div> 

發現的非Ajax版本例如通過$(document).ready()

$(document).ready(function(){ 
    var json = { 
     type: "text/javascript", 
     scriptSrc: "http://www.google.com/recaptcha/api/challenge?k=6LcXq-oSAAAAAOgwSIew_xq6xkv1QUxrZbRcMz6n", 
     id: "theFrame", 
     iframeSrc: 'http://www.google.com/recaptcha/api/noscript?k=6LcXq-oSAAAAAOgwSIew_xq6xkv1QUxrZbRcMz6n' 
    }; 

    var script = document.createElement('script'); 
    script.type = json.type; 
    script.src = json.scriptSrc; 

    $('<iframe>', { 
     src: json.iframeSrc, 
     id: json.id, 
     frameborder: 0, 
     height: 300, 
     width: 500 
     }).appendTo('#recap'); 
}); 

的jsfiddle得到加載:JSfiddle

欲瞭解更多信息,檢查出原始來源:Mixing jQuery and reCaptcha

+0

這是使用AJAX版本的ReCaptcha,我使用的是「正常」版本。 –

+0

正常版本是iframe的權利?然後添加css,就像'display:none;'然後沒有人會看到它,給它一個id或class在$(document).ready(function(){$(「#recap」)中使用show ).show();});' – SSpoke

+0

在頁面加載完成後發現了一個注入腳本的解決方案..它會在頁面加載後開始加載ReCaptcha,在Chrome瀏覽器隱身窗口模式'Ctrl + Shift + N'上測試它,不會緩存頁面。 – SSpoke