0

I have a simple WKWebview.

At first, I am able to get its height once the webview is loaded.

   func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        webView.evaluateJavaScript("document.body.scrollHeight;") { (result, error) in
            if error == nil, let value = result {
                if let height = value as? Int {
                    // found the webview's height here.
                }
            }
        }
   }

But after this, I need to get the webview's height while typing. How to achieve this in iOS, swift?

1 Answers1

1

No need to use a timer, just add an event listener into your input in wkwebview (see here how to do this, similar to textViewDidChange on iOS) and invoke there:

webView.evaluateJavaScript("document.body.scrollHeight;") { (result, error) in
            if error == nil, let value = result {
                if let height = value as? Int {
                    // found the webview's height here.
                }
            }
        }
Henadzi Rabkin
  • 6,834
  • 3
  • 32
  • 39