10

Is it possible to change the IE document mode with Javascript? I won't get into the nitty-gritty details here, but I'm fighting with a locked down Drupal site that will not allow me any acces to edit the theme files. Obviously, the correct thing to do would be to write something into the head, like this:

<meta http-equiv="X-UA-Compatible" content="IE=8">

But, as I mentioned, I have no access to that part of the page, so I'm hoping that I can use Javascript... sort of like this:

document.getElementsByTagName('head')[0].appendChild('<meta http-equiv="X-UA-Compatible" content="IE=IEVersion">');

Sadly, this doesn't work.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Sam
  • 2,152
  • 6
  • 31
  • 44
  • 2
    It'd be really nice if this were possible, but I fear it isn't. – Pointy Mar 15 '11 at 21:55
  • do you have access to the web server? you could serve the X-UA-Compatible HTTP header with the page if so. – Matty F Mar 16 '11 at 11:23
  • @matty I wish! No. Unfortunately, I have very limited access. Basically, I can't edit any Drupal files or theme files or add new ones. I can only interact with the structure of the site by way of Javascript. Sadly, I think this is a lost cause. – Sam Mar 16 '11 at 12:44
  • 1
    I think this header is rather useless given that you can deliver CSS fixes to specific versions of IE. What is the reason you're hoping to add it? – Matty F Mar 18 '11 at 01:17
  • There is something somewhere *very wrong*, if you find yourself needing this. There's surely a better way. Perhaps you should expand on those "nitty-gritty details". – thirtydot Mar 20 '11 at 02:58

1 Answers1

0

That's a bit of a pickle you're in. What about this?

if (navigator.userAgent.indexOf("MSIE 7.0")) {
    // add conditional css in here
} else {
    // default css
}
Michael McTiernan
  • 5,153
  • 2
  • 25
  • 16
  • It's kind of clunky, but it'll do; thanks! If only I had access to edit the head content, this wouldn't even be an issue (sigh...). I should be able to proceed in this direction though. – Sam Mar 21 '11 at 15:50
  • 1
    without "!= -1" this will not works,here indexof returns number not true/false.change code `if (navigator.userAgent.indexOf("MSIE 7.0") != -1)`if dont want to accept "Edit suggestion". – Jubin Patel Feb 13 '13 at 08:34