“scrollHeight” not updated in “onscroll” event handler when using HtmlCtrl in an application but works correctly in IE

Answered “scrollHeight” not updated in “onscroll” event handler when using HtmlCtrl in an application but works correctly in IE

  • Saturday, April 28, 2012 8:24 AM
     
      Has Code

    When sample below code loads in IE9, it works correctly, but when loads in an html control in an application, 'scrollHeight' not updated in 'onscroll' event handler when I change the innerHTML content in the handler, and therefore the alert not to be displayed.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html> <head> <script> function f() { var nBodyHeightOld = document.getElementById("div1").scrollHeight; document.getElementById("div1").innerHTML += '<div>It is a test!</div>'; if (document.getElementById("div1").scrollHeight != nBodyHeightOld) alert('scrollHeight changed!'); } </script> </head> <body> <div id='div1' style='overflow:scroll; height:300px' onscroll="f()"> <div style='height:400px'></div> </div> </body> </html>



    • Edited by mkhani Saturday, April 28, 2012 10:21 AM
    •  

All Replies

  • Sunday, April 29, 2012 8:50 PM
     
     Answered

    the html control in a WPF application will use IE7 emulation mode by default...

    In IE9 test by using the Compatibility View button or Developer tool to force the browser into IE7 Emulation mode.

    You are using the xhtml DTD but you do not have a value for the xmlns attribute of the html tag.


    Rob^_^


  • Monday, April 30, 2012 2:03 PM
     
     Answered Has Code
    add this meta tag
    <html>
       <head>
          <meta http-equiv="X-UA-Compatible" content="IE=9">
       </head>
       <body>
       </body>
    </html>


  • Tuesday, May 01, 2012 7:11 AM
     
     

    use IE=Edge to future proof your markup... IE10 is in Beta...

    you also need a valid dtd and validate your markup at validator.w3.org


    Rob^_^