3

I want to set the height of WebBrowser control dynamically, depending on the content height.

My scenario is: On that specific view I have different elements - an Image, MediaElement etc. and between those rich text that is presented in that WebBrowser control. To achieve unified scrolling I have wrapped all content in a scrollview and disabled scrolling on the webbrowser control.

Currently I have a JavaScript method that gets called when body has done loading and sends the height information to C# codebehind but the calculated height is incorrect.

My hack today is to basically multiply the returned value with about 1.75.

In the page head I have the following meta tags:

<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' />

This is my body tag.

<body onLoad="SendDataToPhoneApp()" style="margin:0px;padding:0px;">

My JavaScript functions:

<script>
    function getDocHeight() {
        return document.getElementById('pageWrapper').offsetHeight;
    }
    function SendDataToPhoneApp() {
        window.external.Notify('' + getDocHeight());
    }
</script>

pageWrapper is a direct child of body.

texmex5
  • 4,354
  • 1
  • 26
  • 28
  • It looks like you're trying an aproach suggested by the answer to this question: http://stackoverflow.com/questions/4684307/any-way-to-set-the-wp7-webbrowser-control-height-dynamically-and-lock-scrolling I'd recommend trying 'document.body.clientHeight'. I don't know which element you have with an id of 'pageWrapper'. If you can provide more details about the height value you're getting back and the value you're expecting that will help. Which element has the 'pageWrapper' id on it? Also, I'm curious about your scenario. Why do you want to set the WebBrowser height to the content height? – Skeets May 25 '11 at 18:56

1 Answers1

4

Try using document.body.clientHeight in your Javascript. Also you might have better luck with your scenario if you construct everything inside the WebBrowser. You can put images in the HTML of course and you could put a still-frame placeholder image for your MediaElement, calling back into C# and poping up a real MediaElement when needed.

Skeets
  • 1,252
  • 11
  • 16
  • Well it kind of is a solution and I'll mark it as an correct answer but I still don't know why the values from offsetHeight are incorrect. – texmex5 Jun 04 '11 at 12:07
  • 1
    I don't know either. These pages are not directly related to your problem but you may find them to be helpful background info (the second is what led me to suggest you use body.clientHeight) http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/03/14/managing-the-windows-phone-browser-viewport.aspx, http://www.quirksmode.org/mobile/viewports2.html – Skeets Jun 06 '11 at 21:17