我使用 wkwebview 并在 View Controller 中显示验证码。验证码显示很小,但双击它会自动对齐。我怎样才能使它自动化。
我用 wkwebview 委托(delegate)尝试这个。
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
print("")
webView.scrollView.zoom(to: CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height), animated: true)
}
但是对齐不正确。
问候
最佳答案
在你的 html 文件中尝试这个脚本
<head><title>Captcha</title><script src="https://www.google.com/recaptcha/api.js" async defer></script><script type="text/javascript">
(function() {
var RECAPTCHA_SITE_KEY = 'YOUR_KEY';
var RECAPTCHA_THEME = 'dark';
var PAGE_BG_COLOR = '#222';
function waitReady() {
if (document.readyState == 'complete')
documentReady();
else
setTimeout(waitReady, 100);
}
function documentReady() {
while (document.body.lastChild)
document.body.removeChild(document.body.lastChild);
var div = document.createElement('div');
div.style.position = 'absolute';
div.style.top = '50%';
div.style.left = 'calc(50% - 151px)';
document.body.style.backgroundColor = PAGE_BG_COLOR;
document.body.appendChild(div);
var meta = document.createElement('meta');
meta.setAttribute('name', 'viewport');
meta.setAttribute('content', 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0');
document.head.appendChild(meta);
showCaptcha(div);
}
function showCaptcha(el) {
try {
grecaptcha.render(el, {
'sitekey': RECAPTCHA_SITE_KEY,
'theme': RECAPTCHA_THEME,
'callback': captchaSolved,
'expired-callback': captchaExpired,
});
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["didLoad"]);
} catch (_) {
window.setTimeout(function() { showCaptcha(el) }, 50);
}
}
function captchaSolved(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["didSolve", response]);
}
function captchaExpired(response) {
window.webkit.messageHandlers.reCaptchaiOS.postMessage(["didExpire"]);
}
waitReady();
})();
function captchaSolved(){alert("working");}</script></head><body><form action="?" method="POST"><div class="g-recaptcha" data-callback="captchaSolved" data-sitekey=""></div><br/><div class="g-recaptcha-response"></div></form></body>
关于ios - 自动化 wkwebview 双击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49803367/