0

Suddenly I’m experiencing something strange with document.getElementsByClassName in my website.

Here is what happened:

I am running an aspx website on IIS7.0 where some parts of my JavaScript code uses document.getElementsByClassName. I never experienced any problems with this on Firefox, Chrome or IE8+

Today, I’m migrating my website to a new server, which runs IIS7.0 as well.

I copied my website, and suddenly document.getElementsByClassName is not recognized any more by IE8+ (it works normally in Chrome and Firefox though...)

I know there is a workaround for this issue described here: javascript document.getElementsByClassName compatibility with IE but that is not the question.

My question is: how is it possible that document.getElementsByClassName no longer works, while I just copied my website?

Is their something to be changed on the new server, IIS, … ?

Many thanks,

Community
  • 1
  • 1
quintroo
  • 75
  • 1
  • 8
  • You checked it earlier on IE8? – void Jan 04 '16 at 15:17
  • I did, it worked on IE8+. Anyway, by example, my old website is still working fine on IE11, but the new one is not on IE11. – quintroo Jan 04 '16 at 15:18
  • How did you know it was `getElementsByClassName`? Did you check the console? or did you just suspect? – Joseph Jan 04 '16 at 15:19
  • Hm. Caniuse.com at least, disagrees with your seal of IE8 approval: http://caniuse.com/#search=getelementsby. Anyway, if it's not working on IE11, check what compatibility mode the site is in, using the F12 menu. There are a number of situations where IE11 might automatically try to show the site in IE7 compatibility mode. – Katana314 Jan 04 '16 at 15:19
  • @Katana314 I was in the assumption it worked on IE8. But the question remains, why is the new website not working on e.g. IE11 but the old one does work on IE11 – quintroo Jan 04 '16 at 15:24
  • @JosephtheDreamer console: Object doesn't support property or method 'getElementsByClassName' – quintroo Jan 04 '16 at 15:25
  • 1
    What does the console say? – Mic Jan 04 '16 at 15:27
  • @Mic `Object doesn't support property or method 'getElementsByClassName'` – quintroo Jan 04 '16 at 15:29
  • There's your problem. `document` may not be what you think it is. – Joseph Jan 04 '16 at 15:30
  • @Tom have you set the `doctype` property? – Sudhansu Choudhary Jan 04 '16 at 15:30
  • @JosephtheDreamer How do you mean? I just copied my website? – quintroo Jan 04 '16 at 15:32
  • 2
    @Tom The major change to this working app is the change of server. I'm pretty sure my comment above is a much more likely cause for the issue than Joseph's prediction of coding mistakes. Sudhansu gave a good suggestion as to the reason Compatibility Mode is being changed, but ultimately, that's the thing you have to check. Read my earlier comment. – Katana314 Jan 04 '16 at 15:33
  • @Katana314 Many thanks. We website was rendering in IE7. I've changed my web.config and now it works – quintroo Jan 04 '16 at 15:47
  • @Tom Whenever you have IE compatibility issue, please look at "IE Compatibility/Standard mode", to be put straight forward!! Observe the mode in which it is functioning.. javaScript ain't that buggy also to stop supporting their built in functions...!! It's the browser!! Finally that's what decides and renders what it does!! – Sudhansu Choudhary Jan 04 '16 at 20:44

2 Answers2

1

The major change to this working app is the change of server. I'm pretty sure my comment above is a much more likely cause for the issue than Joseph's prediction of coding mistakes. Sudhansu gave a good suggestion as to the reason Compatibility Mode is being changed, but ultimately, that's the thing you have to check. Read my earlier comment.

– Katana314

quintroo
  • 75
  • 1
  • 8
1

Already suggested in comments, but to wrap up as answer:

If a working IE11 site suddenly stops working on another server, and the connection string's structure has changed in some way, the most likely cause is that IE11 believes it's viewing an old intranet site, and pessimistically uses IE7 mode for maximum compatibility. A few other things can cause this, like having an unreadable or old <!DOCTYPE at the beginning of the page.

You can change IE11's default compatibility settings to fix the issue locally, use a fully-qualified domain name, or there are some <meta> tags or HTTP response headers you can add to change IE's default behavior. Microsoft would likely have more informative articles on their own site.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Katana314
  • 8,429
  • 2
  • 28
  • 36