How do you resize a webbrowser control to fit on a html element?

I thought I had found the solution to this problem in the following question, but it does not behave as planned.

http://stackoverflow.com/questions/6094766/windows-phone-7-webbrowser-content-height

So I am pretty much struggling with this, but I guess if the answers can go in here it will be as useful on here than it is on stack overflow

I am loading some html content into a div that is inside of a webbrowser control, when the page has loaded I pass the height of the div back to the control with this.

onLoad="window.external.notify(''+document.getElementById('content').offsetHeight);"

and in the ScriptNotify call back i’m currently doing to something like this

private void PlayerBrowser_ScriptNotify(object sender, NotifyEventArgs e)
{
   PlayerBrowser.Height = Convert.ToDouble(e.Value) * 0.5;
}

some values return but when the content is snug at the top of the webbrowser control i will truncate some of the content from the bottom.

and when i adjust the height (by changing 0.5 to another number) so that there should be more than enough space to fit the content in, it will centre it all vertically and then still truncate the bottom of the control.

my html is being specified like this.

string newHtmlString = "<head><meta charset='Windows-1257'><meta name='viewport' content='width=device-width' />" +
  "<meta name='viewport' content='user-scalable=no' /><meta name='viewport' content='initial-scale = 1.0' />" +
  "<meta name='HandheldFriendly' content='true' /><meta name='target-densitydpi=device-dpi' /></head>";

newHtmlString += "<body        onLoad="window.external.notify(''+document.getElementById('content').offsetHeight);" ><div id='content'>";            
newHtmlString += htmlContent + "</div></body>";

this code is closest i’ve found up to now for the solution to my problem, so It would be nice for someone to let me know where I have gone wrong.

This entry was posted in Uncategorized by admin. Bookmark the permalink.

Comments are closed.