Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hello, I don't know if I can get the height of InAppWebView or make it adapt to the height of Html content. What do I need to do? #35

Open
JiangJuHong opened this issue Jan 5, 2019 · 8 comments

Comments

@JiangJuHong
Copy link

Hello, I don't know if I can get the height of InAppWebView or make it adapt to the height of Html content. What do I need to do?

@shah-xad
Copy link

Did you find any idea?

@juliengit2
Copy link

juliengit2 commented Mar 11, 2019

I had to add:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
to adapt the size of the html content to the size of the InAppWebView

@YouCii
Copy link
Contributor

YouCii commented Mar 12, 2019

@juliengit2 The code only allows HTML pages to be adapted to mobile devices, but the height is not the biggest.

@honghuazhao
Copy link

You can inject js code to do this, like:

controller.injectScriptCode('''
window.flutter_inappbrowser.callHandler('WebViewHeight', document.body.scrollHeight);
''');

But you still cannot set the height of InAppWebView to this height. It will crash on android because android (or flutter) doesn't support height more than device height.

@goYou
Copy link

goYou commented Apr 16, 2020

This may help you:

onLoadStop: (InAppWebViewController controller, String url) {
              controller.evaluateJavascript(source: '''(() => { return document.body.scrollHeight;})()''').then((value) {
                if(value == null || value == '') {
                  return;
                }
                webHeight = double.parse('$value');
                setState(() {});
              });
            },

@sketcharsh
Copy link

This can also give you same result.

controller .getContentHeight() .then((value) => print("Value $value"));

@wilz05
Copy link

wilz05 commented Jan 4, 2022

but the above code does not work on android api version 22 devices. have you tried ? @sketcharsh @goYou

@sketcharsh
Copy link

I've not checked in android api version 22 devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants