function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michal KozakMichal Kozak 

Unable to set compatibility meta tag from controller

Hello,

I am trying to set meta tag X-UA-Compatible from controller. I need to do it from controller because it will be dependant on other factors.
I have googled quite a bit, found several examples and solutions, but none seem to work for me.

I have created a simple page and controller so hopefully someone can tell me what I am doing wrong:

Page:
<apex:page docType="html-5.0" controller="ieCompatibility" standardStylesheets="false" showHeader="false" sidebar="false">
 The content
</apex:page>

ieCompatibility class:
public class ieCompatibility {

    public ieCompatibility() {
        Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8'); 
    }
}

The generated markup:
<!DOCTYPE HTML>
<html><head><script src="/static/111213/js/perf/stub.js" type="text/javascript"></script></head><body>
 The content</body></html

Thank you for suggestions.
Vishal_GuptaVishal_Gupta
Hi Michal,

Please give a try with following steps :

1) Create a javascript function say AddMetaTag()
function AddMetaTag()
{
var meta = document.createElement('meta');
meta.setAttribute('http-equiv', 'X-UA-Compatible');
meta.setAttribute('content', 'IE=8');
document.getElementsByTagName('head')[0].appendChild(meta);
}
2) Call this method on the basis of your dependent factor and set different values in it.

Please let me know if I can help you more.

Thanks,
Vishal
 
Michal KozakMichal Kozak
Hi Vishal Gupta 16, thanks for the suggestion, but this won't work.
The tag needs to be there when the page is beeing loaded - thus returned by the server. Adding the header in the runtime by javasceript is simply too late and is not going to work.
Muthuraj TMuthuraj T

Hi,

Please refer this help article.

https://help.salesforce.com/apex/HTViewSolution?id=000175466&language=en_US


Internet Explorer has a strict implementation of the x-ua-compatible META tag in this scenario.  Specifically, it is required to be directly at the top of the HEAD element.
 
Since you cannot control this at the Visualforce layer, it is recommended you set the header as follows within the controller constructor: Apexpages.currentPage().getHeaders().put('X-UA-Compatible', 'IE=8')