WebView returns bad window.innerHeight

前端 未结 4 1110
太阳男子
太阳男子 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:59

    I used this:

    Java code in Activity:

    webView.addJavascriptInterface(new WebAppInterface(this), "Android");
    

    ...

    public class WebAppInterface {
        Context mContext;
    
        WebAppInterface(Context c) {
            mContext = c;
        }
    
        public int getWinHeight() {
          return webView.getHeight();
        }
    }
    

    JS code:

    var winHeight = Android.getWinHeight();
    

提交回复
热议问题