3

Is it possible to alter the X-UA-Compatible meta tag using jQuery? I am currently working on a page that will be embedded on another page through an iFrame. The parent document currently sets the X-UA-Compatible tag to Edge, which breaks my frame completely. I wish to somehow force the parent document to reload the page but apply IE8 standards.

Right now I'm calling

$("meta[name=X-UA-Compatible]", top.document).attr('content', 'IE=8'); 

which is not functioning. I am beginning to think this is simply not possible as even within the frame I am working on I am not able to change this attribute in a way that significantly alters how IE9 parses it.

I am looking at this chart: https://i.stack.imgur.com/e5gPv.png and it appears I can only switch the frame to either Quirks or IE9, which is very inconvenient. Does anyone have any ideas? Perhaps there is an ajax solution that I am simply not seeing..

2 Answers 2

2

So I finally figured this out, Here's the code that needs to be placed in your frame HTML if you need to reload the frame..

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
if($('meta[http-equiv=X-UA-Compatible]', top.document).attr('content')!='IE=8') 
{
//alert('adjusting IE compatibility');
$('meta[http-equiv="X-UA-Compatible"]', top.document).attr('content', 'IE=8');
$('meta[http-equiv="X-UA-Compatible"]').attr('content', 'IE=8');
$('#FRAMEID',window.parent.document).attr('src',$('#FRAMEID',window.parent.document).attr('src'));
}
</script>

it's still undergoing testing to confirm that the parser legitimately changes, but for now this is the best quick fix we got.

1

In your line of code, you're missing a bracket after "[name=X-UA-Compatible".
Could that be the issue?

Also, do you not have control over the code of the top page, and is it on the same domain?

5
  • no that wasn't the issue, though I appreciate the attention. My actual code is more properly formatted. it is the same domain, but we don't have direct control over the code on the top page. also, $('meta[name=X-UA-Compatible]').attr('content', 'IE=8'); doesn't work either, even outside of the frame itself. I'm starting to think once IE processes the DOM, no amount of javascript in the universe will change the document mode...
    – Xax D
    Jun 26, 2012 at 1:15
  • That's actually quite likely, given that IE actually uses an entirely different JS implementation when it's running in quirks mode. Have you tried changing document.doctype? (IIRC, you can change the IE mode via doctype, not just metatag)
    – Lusitanian
    Jun 26, 2012 at 1:23
  • Nevermind...that's a read-only property. From what I'm reading, though, IE renders iframes totally separately from the parent so you should be able to set the meta tag within the iframe.
    – Lusitanian
    Jun 26, 2012 at 1:25
  • should being the keyword. thanks for your valuable time. I'm beginning to think the meta data is being altered, but it doesn't matter after-the-fact (once the headers are loaded)..
    – Xax D
    Jun 26, 2012 at 1:30
  • Indeed. Heh, sorry I couldn't help more. If nothing else, maybe you could get the person with the control over the top page to add server-side code that adds the UA-Compatible meta tag if there's a GET param fromiframe=1, then force the top page to reload with that parameter in your JS. Somewhat unobtrusive.
    – Lusitanian
    Jun 26, 2012 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.