Get WebView's content height - Windows Phone 8.1

纵饮孤独 提交于 2020-01-05 15:16:46

问题


I try to get the height of the actual HTML content inside my WebView in order to set the height according to the content.

this is my script, but I get an empty string when the scripit is being invoked.

      private async Task LoadHTMLContent(ItemViewModel itemVm)
    {
        var htmlScript = "<script>function getDocHeight() { " +
                      "return document.getElementById('pageWrapper').offsetHeight; } </script>";

        var htmlConcat = string.Format("<html><head>{0}</head>" +
                                        "<body style=\"margin:0;padding:0;\" " +
                                        ">" +
                                        "<div id=\"pageWrapper\" style=\"width:100%;" +
                                        "\">{1}</div></body></html>", htmlScript, itemVm.Model.Content);

        webView.NavigationCompleted += webView_NavigationCompleted;
        webView.NavigateToString(htmlConcat);


    }

    async void webView_NavigationCompleted(WebView sender, WebViewNavigationCompletedEventArgs args)
    {
        string pageContentHeight = await webView.InvokeScriptAsync("getDocHeight", null);

    }

回答1:


Well, I found a solution.

If you wish to do the same, feel welcome to check out my solution on GitHub: https://github.com/romshiri/sizeable-webview



来源:https://stackoverflow.com/questions/29304540/get-webviews-content-height-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!