获取 WebView 的内容高度 - Windows Phone 8.1 [英] Get WebView's content height - Windows Phone 8.1
本文介绍了获取 WebView 的内容高度 - Windows Phone 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试获取 WebView 中实际 HTML 内容的高度,以便根据内容设置高度.
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);
}
推荐答案
好吧,我找到了解决方案.
Well, I found a solution.
如果你也想这样做,欢迎在 GitHub 上查看我的解决方案:https://github.com/romshiri/sizeable-webview
If you wish to do the same, feel welcome to check out my solution on GitHub: https://github.com/romshiri/sizeable-webview
这篇关于获取 WebView 的内容高度 - Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文