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不能访问的网络中使用。 –