无法在“窗口”上执行“ postMessage”:未找到与提供的签名匹配的功能

时间:2018-10-10 12:53:23

标签: react-native webview

var _d = document, _w = window;
    var _postMessage = function(message) {
        _w.postMessage(message);
    };
    function loadScript(url) {
        var _script = _d.createElement('script');
        _script.type = 'text/javascript';

        if (_script.readyState) {
            _script.onreadystatechange = function() {
                var _readyState = _script.readyState;
                if (_readyState === 'loaded' || _readyState === 'complete') {
                    _script.onreadystatechange = null;
                    _postMessage('LOADED');
                }
            }
        } else {
            _script.onload = function() {
                _postMessage('LOADED');
            }
        }

        _script.src = url;
        var s = _d.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(_script, s);
    }
loadScript('https://www.google.com/recaptcha/api.js');

我想在加载脚本时发布消息,但是出了点问题。

`var verifyCallback = function(response) {
        _postMessage(response);
    };

    var onloadCallback = function() {
        grecaptcha.render('reCaptcha', {
            'sitekey': 'XXXXXXXXXXX',
            'callback': verifyCallback,
        });
    };`

在验证成功后发送消息时,就可以了。

请帮助我,谢谢!

0 个答案:

没有答案