WebView returns bad window.innerHeight

前端 未结 4 1124
太阳男子
太阳男子 2021-02-14 01:23

I have an application that makes use of the Android WebView, as well as some JavaScript. When my WebViewClient calls onPageFinished(), I alert my JavaScript to run

4条回答
  •  悲哀的现实
    2021-02-14 01:54

    This is because Javascript executes before WebView's View related initialization. And Android WebView returns a 320x240 default value to JS. Execute your JS after some time is ok, like this

    function go() {
    int height = view.getHeight();
    int width = view.getWidth();
    };
    window.setTimeout(go, 300);
    

提交回复
热议问题