自动化wkwebview双击

时间:2018-04-12 18:12:37

标签: ios swift wkwebview

我使用wkwebview并在视图控制器中显示验证码。验证码显示很小,但双击它会自动对齐。我怎么能自动化呢。

enter image description here

我试着用wkwebview委托。

ax.plot

但它对齐不正确。

问候

enter image description here

1 个答案:

答案 0 :(得分:1)

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