ios - 自动化 wkwebview 双击

标签 ios swift wkwebview

我使用 wkwebview 并在 View Controller 中显示验证码。验证码显示很小,但双击它会自动对齐。我怎样才能使它自动化。

enter image description here

我用 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)
}

但是对齐不正确。

问候

enter image description here

最佳答案

在你的 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/

相关文章:

ios - sqlite3_open 返回错误代码 23,即 SQLITE_AUTH

ios - Swift + Storyboards : segue. 标识符在 iPad 上崩溃(iPhone 正常)

ios - 如何从 WKHttpCookieStore 中删除 cookie?

ios - 开发iOS框架时如何在WKWebView中加载本地HTML文件

ios - 在 Objective-C 中解析字符串中的所有整数

ios - 使用图像初始化对象

ios - 在 UITableViewCell 上设置 JSON 值时出错

ios - 不想按排序顺序对参数进行排序 alamofire

swift - Swift 中的类内部协议(protocol)

swift - 如何以编程方式滚动 iOS WKWebView,swift 4