The height of content is incorrect when WKWebview is used to display text or html

1.  When display text or html content with wkwebview, the height would be smaller than the actual height(the scroll bar will be displayed).

2. Open the content  on IPAD in portrait mode, then the content height will be much greater than its actual height when changing to landscape mode (There is space under the bottom).

 

In order to adjust screen size, the js code as below is added.

var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport');
meta.setAttribute('content', 'width=device-width');
document.getElementsByTagName('head')[0].appendChild(meta);

 

in order to get the height of WKWebview’s content when WKWebView has been loaded. the js code as below is added.

webview.evaluateJavaScript("document.body.scrollHeight"){.......

 

Before rotation, Both the height and zoom properties of WKWebView are setted to 0 and 1.0 respectively. After rotation, the WKWebView is reloaded.


Please advice how to fix the issues.


Powered by WPeMatico

You may also like...

Comments are closed.