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,
});
};`
在验证成功后发送消息时,就可以了。
请帮助我,谢谢!