如何在有或没有javaScript的android中获取每个页面的内容高度

How to get the content height of each page in android with or without javaScript?

本文关键字:高度 获取 android javaScript      更新时间:2023-09-26

我想逐个获取每个网页的内容高度。但我不明白。如果我单独加载页面,那么我能够获得每个页面的高度。但是,如果我试图连续获取网页的内容高度,那么我失败了。

这是我的代码-

StringBuffer content;
     String temp;
         for(i=tempstart_index;i<=tempend_index;i++)
                {
                Log.i("value of i",i+1+"");
                content+=decrypted(i);
                temp1=decrypted(i);
                // TODO Auto-generated method stub
                webview.setWebViewClient(new WebClient());
                {
                    @Override
                    public void onPageFinished(WebView view, String url)
                    {
                        webview.loadUrl("javascript:window.HTMLOUT.getContentHeight(document.getElementsByTagName('html')[0].scrollHeight);");
                        int initialpageheight=webview.getContentHeight();
                        if(initialpageheight>0)
                        {
                            webheight=initialpageheight;
                            //Toast.makeText(getApplicationContext(), ""+initialpageheight, Toast.LENGTH_LONG).show();
                            Log.i("page finish","" +webheight);
                            initialpage=webheight;
                            if(pagenumber>0)
                            {
                            webview.scrollTo(0, webheight);
                            }
                                         }
         }});
         webview.loadDataWithBaseURL("file:///android_asset/KH_Brown_Fixed_Layout/",temp1,
     "text/html", "utf-8",null);
                }
         return content;
         }

然后我在合并字符串后将所有合并的页面显示为一页-

/

/这里 reflowable() 读取 HTML 并合并它们,合并后返回它。

 String ds=reflowable();
                webview.loadDataWithBaseURL("file:///android_asset/KH_Brown_Fixed_Layout/", ds, "text/html", "utf-8", null);    

在 JavaScript 中,您可以使用以下命令在 webkit 浏览器上获取页面的高度:

window.innerHeight

至于你在那里尝试了什么,我不知道,但这会给你安卓浏览器中的高度。