我正在使用简单的谷歌验证码。
我的要求是,如果谷歌API不可用(即如果谷歌服务器关闭,知道它不常见的情况)意味着没有从谷歌服务器得到任何回复,那么在加载表单时我将隐藏谷歌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;
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)