Reputation: 9645
I really need to be able to work out how tall a piece of HTML is inside a given WebView
. It's pretty much crucial to the project I'm trying to build. I know it's not immediately possible but I could determine whether a scrollbar existed on a WebView I might be able to increase the height of the view until it disappeared.
Any thoughts on this? Or any alternative solutions / suggestions? I looked into converting it for a TextBlock using the HTMLAgilityPack (now ported to Metro) but the HTML is too complex for that.
Upvotes: 3
Views: 2132
Reputation: 307
This may be a good solution but there is still a problem with device pixel density. If you run your code on WP the conversion may look like this:
private double PixelsToLogicalPixels(double pixels)
{
var info=Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
return pixels / info.RawPixelsPerViewPixel;
}
private double LogicalPixelsToPixels(double pixels)
{
var info = Windows.Graphics.Display.DisplayInformation.GetForCurrentView();
return pixels * info.RawPixelsPerViewPixel;
}
Upvotes: 0
Reputation: 42013
If you have control over the HTML, add this javascript:
function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}
(from http://james.padolsey.com/javascript/get-document-height-cross-browser/)
And call this rather than alert
:
window.external.notify(getDocHeight());
Then implement the ScriptNotify
event:
Upvotes: 8