1
我正在使用簡單的谷歌recaptcha。 我的要求是,如果谷歌API是不可用的(即如果谷歌服務器關閉,知道它不常見的情況下)意味着沒有從谷歌服務器得到任何答覆,然後編寫表單時,我會隱藏谷歌reCaptcha包裝,同時提交表單我不想驗證谷歌recaptcha。檢查谷歌reCaptcha服務是打開還是關閉
請建議我該如何做到這一點。
我正在使用簡單的谷歌recaptcha。 我的要求是,如果谷歌API是不可用的(即如果谷歌服務器關閉,知道它不常見的情況下)意味着沒有從谷歌服務器得到任何答覆,然後編寫表單時,我會隱藏谷歌reCaptcha包裝,同時提交表單我不想驗證谷歌recaptcha。檢查谷歌reCaptcha服務是打開還是關閉
請建議我該如何做到這一點。
谷歌不提供這些數據(假設它們總是在運行)。
但你可以這樣做。動態加載腳本並檢查回調中存在的event
。如果沒有event
可用,則失敗。 查看@example
的使用評論。
var setAttributes = function (el, attrs) {
/**
* @method simple for in loop to help with creating elements programatically
* @param {object} el - HTMLElement attributes are getting added to
* @param {object} attrs - object literal with key/values for desired attributes
* @example setAttributes(info,{
* 'id' : 'info'
* 'class' : 'my-class-name'
* });
*/
'use strict';
var key;
for (key in attrs) {
if (attrs.hasOwnProperty(key)) {
el.setAttribute(key, attrs[key]);
}
}
return el;
};
var getScript = function (url, fullPath) {
/**
* @method dynamically add script tags to the page.
* @param {url} string with relative path and file name - do not include extension
* @param {fullPath} string with absolute path
* @example getScript('FrameAdjustChild');
* @example getScript('','https://www.google-analytics.com/analytics.js');
*/
'use strict';
var setAtt, PATH = /js/, /* or wherever you keep your scripts */
el = document.createElement('script'),
attrs = {
defer: true,
src: null,
type: 'text/javascript'
};
/** look for a string based, protocol agnostic, js file url */
if (typeof fullPath === 'string' && fullPath.indexOf('http') === 0) {
attrs.src = fullPath;
}
/** look for any string with at least 1 character and prefix our root js dir, then append extension */
if (typeof url === 'string' && url.length >= 1) {
attrs.src = PATH + url + '.js';
}
setAtt = setAttributes(el,attrs);
el.addEventListener('load', function (event) {
if (event) {
/* status is good */
}
else {
/* status is bad */
}
}, false);
document.body.appendChild(el);
return el;
};
可以可能應用程序了將從其中谷歌API不能訪問的網絡中使用。 –