To programmatically disable IE-8 compatibility mode for the site running in intranet and rendering .xhtml pages

断了今生、忘了曾经 提交于 2019-12-08 02:41:21

问题


I have a JSF application with .xhtml pages running in intranet.I tried removing default meta tag and add the meta tag

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

But there is no use.Is this solution only for plain html pages or is there any other way using which i can programmatically disable compatibility mode.


回答1:


If you want to prevent the compatibility mode for all your JSF pages you better use a filter for this:

Java

public class NoCompatibilityMode implements Filter {

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException,
            ServletException {
        if (((HttpServletRequest) req).getRequestURI().endsWith(".js.jsf")
                || ((HttpServletRequest) req).getRequestURI().endsWith(".css.jsf")) {
            chain.doFilter(req, res);
        } else {
            HttpServletResponse response = (HttpServletResponse) res;
            response.setHeader("X-UA-Compatible", "IE=edge"); // No more Compatibility Mode
            chain.doFilter(req, res);
        }

    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {
    }

}

web.xml

<filter>
    <filter-name>NoCompatibilityMode</filter-name>
    <filter-class>my.package.name.NoCompatibilityMode</filter-class>
</filter>
<filter-mapping>
    <filter-name>NoCompatibilityMode</filter-name>
    <url-pattern>*.jsf</url-pattern>
</filter-mapping>


来源:https://stackoverflow.com/questions/22315643/to-programmatically-disable-ie-8-compatibility-mode-for-the-site-running-in-intr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!