Friday, May 28, 2010

offsetHeight is 0 in Internet Explorer

Recently I had interesting issue while testing project in Internet Explorer. I have iframe burried under a long list of elements whose parent's height is updated by AJAX callback from iframe itself depending on iframe content height. In other browser everything works smoothly but in IE there is issue that document.body.offsetHeight is 0. I was digging issue and tried to debug it and finally noticed that when I stop with debug on the line that returns height - it showed correct number - and without debug still zero. I noticed that I had document.body opened on my watch list. After removing it - offsetHeight is again 0.

So there was some element in document.body that after being called, fixed offsetHeight to normal. And after small hack
    for (val in document.body) {
      var before = document.body.offsetHeight;
      if (before != document.body.offsetHeight) {
I found that this magic element is filters and when it is called like
it magically fixes documents offsetHeight.

No comments:

Post a Comment