2

Short Version

Trying to access the document.documentElement.offsetHeight on IEMobile 7.11 throws an unspecified error. Why?

Long Version

I'm working on fixing some Javascript meant to be run on handheld devices (not phones, the kind delivery guys use). The devices have a few different OSes and browser versions, though, so compatibility is a concern.

The problem code is in a method called during the body element's onLoad and onResize events. I was able to fix the problem on one device using the document.documentElement.offsetHeight property, but when I try to use it on the other device, it gives an error.

Now, I was expecting to have to do all sorts of quirky compatibility checks, but this particular error is interesting because I have no idea why it's happening. All of the following cause an error:

var str = document.documentElement.offsetHeight
var str = String(document.documentElement.offsetHeight)
alert(document.documentElement.offsetHeight)

So it appears that simply trying to access the property at all throws the error. I checked that the documentElement object exists, and it does, so it's not a case of calling properties on a null. I thought it might be because offsetHeight isn't defined, even though that should just return null, so I checked the documentElement's properties with the following loop to be sure:

var str = "";
for (var prop in document.documentElement) {
    str += prop + "\n";
}

But the offsetHeight property is definitely there on the object, although I have no idea what value it is.

I tried catching the error, and it didn't give me anything helpful; both the error.description and error.message were empty, so I looked up the error number (-2147467259) and found it means "Unspecified Error", short for "you're on your own".

As far as my own knowledge goes, this error is completely inexplicable. So I come to Stack Overflow seeking wisdom.

Miscellaneous Info

  • OS: Windows Mobile 6.1 Professional
  • Browser: IEMobile 7.11
Reikim
  • 196
  • 1
  • 8
  • http://www.w3schools.com/jsref/prop_element_offsetheight.asp – apandit Aug 17 '15 at 21:49
  • In this: `document.documentElement.style` you're looping though `style`. not `documentElement`. – Downgoat Aug 17 '15 at 21:51
  • Oh, sorry, I copy-pasted that from modified code that I was using to loop through a few different thigns. I'll update it. – Reikim Aug 17 '15 at 21:53
  • @apandit : I'm not sure what you're trying to say there. I checked the w3schools page before coming here, and it didn't have anything relevant to my situation. – Reikim Aug 17 '15 at 21:55
  • @Reikim Sorry...thought you were trying to do something else. Are the lines of code that are giving you the error being called after the document has loaded? – apandit Aug 17 '15 at 22:02
  • To be honest, I'm not entirely sure. It's tied to the body by `onload="problematicFunction();"`, which in theory should only fire after everything's been loaded, but I've seen IE do weirder things before. I thought of that, though, so I bound the function to a button on the page and mashed it, and still got the same error; so it's not because it's trying to access things before load. – Reikim Aug 17 '15 at 22:05
  • @Reikim What does adding `str += document.documentElement[prop] + "\n"` inside the `for` loop give you? Does it error out as well? – apandit Aug 17 '15 at 22:21
  • @apandit Yes, it does. It really does seem like it just doesn't want me to read that one property. Maybe it's a security thing...though that wouldn't make any sense at all. – Reikim Aug 18 '15 at 14:15
  • Is it maybe the content-type coming from the server? Is it "application/javascript" and not "text/javascript". See accepted answer at http://stackoverflow.com/questions/3231827/iemobile-7-11-with-external-javascript – apandit Aug 18 '15 at 14:21
  • No, that's definitely not the problem, because the javascript is in fact running. (I tried it just for kicks, though.) I think I'm just going to write this off as "IEMobile 7 hates you", because I've been playing around with about fifty different workarounds for the original problem and none of them work right for various reasons. – Reikim Aug 18 '15 at 16:09

0 Answers0