首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自动wkwebview双击

自动wkwebview双击
EN

Stack Overflow用户
提问于 2018-04-12 18:12:37
回答 1查看 475关注 0票数 1

我使用wkwebview并在视图控制器中显示captcha。captcha显示是小的,但双击它会自动对齐。我怎么能把它自动化。

我在wkwebview委托中尝试了这一点。

代码语言:javascript
复制
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)
}

但它对齐是不对的。

问候

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-12 19:28:42

在html文件中尝试这个脚本

代码语言:javascript
复制
<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>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49803367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档