检查 google reCaptcha 服务是打开还是关闭 [英] Check google reCaptcha service is on or off

查看:49
本文介绍了检查 google reCaptcha 服务是打开还是关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是简单的 google recaptcha.我的要求是,如果 google api 不可用(即,如果 google 服务器关闭,知道它不是通常的情况)意味着没有从 google 服务器收到任何回复,然后在提交表单时我将隐藏 google reCaptcha 包装器并在提交表单时我不想验证 google recaptcha.

I am using simple google recaptcha. My requirement is that if google api is not available (i.e. if google server is down, know its not usual case) means not getting any reply from google server then while loding the form I will hide the google reCaptcha wrapper and while submitting the form I don't want to validate google recaptcha.

请建议我如何实现这一目标.

Please suggest How can I achieve this.

推荐答案

Google 不提供该数据(假设它们始终可用).

Google does not provide that data (assuming they are always up).

但你可以这样做.动态加载脚本并检查回调中是否存在 event.如果没有 event 可用,则失败.查看 @example 注释以了解用法.

But you could go about it this way. Dynamically load the script and check for the event existence in the callback. If no event is available then it failed. Check out the @example comment for usage.

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;
};

这篇关于检查 google reCaptcha 服务是打开还是关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆