Change IE Document Mode with Javascript?
Asked Answered
N

1

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.

Nore answered 15/3, 2011 at 20:18 Comment(5)
It'd be really nice if this were possible, but I fear it isn't.Tasteful
do you have access to the web server? you could serve the X-UA-Compatible HTTP header with the page if so.Shamefaced
@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.Nore
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?Shamefaced
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".Gordon
P
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
}
Primateship answered 20/3, 2011 at 2:10 Comment(2)
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.Nore
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".Hawking

© 2022 - 2024 — McMap. All rights reserved.