简体   繁体   中英

Setting X-UA-Compatible in http header doesn't change document.documentMode for html in browser

I have an application that supports IE9 (IE10 compatibility mode) and am trying view another application (supports IE10 only) in an IFrame. For the specific pages of the parent application making a call to the pages of the child application I want to render the parent and child pages in "IE=edge" or "IE=10" so that the functionality of the child application works.

I wrote a servlet filter to interpret the request and set the value of User-Agent and X-UA-Compatible. However, the value of document.documentMode still shows as "8" ie IE 8 in javascript when the page is rendered. I am wondering what I am doing incorrectly. Pasted the code snippet below and any help is appreciated:-

public class DocumentsFilter implements Filter {

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain    filterChain) 
                throws IOException, ServletException {

         HttpServletResponse resp = (HttpServletResponse)servletResponse;
         resp.addHeader("X-UA-Compatible", "IE=10");

         String ua = ((HttpServletRequest) servletRequest).getHeader("User-Agent");
         ua = ua.replaceAll("MSIE 7.0", "MSIE 10.0");
         resp.setHeader("User-Agent", ua);

         filterChain.doFilter(servletRequest, servletResponse);

   }

}

Any help is appreciated.

Are you making sure that you are setting the doctype? Old versions of IE automatically revert to quirks mode without it.
http://webdesign.about.com/cs/doctype/a/aaquirksmode.htm

After reading the article it sounds like the is an important element for the browser to decide how to render the page. Even though the X-UA-Compatible flag is set, unless the DocType is set to the appropriate value, the page will render as though it is in older versions of the browser. Please let me know if this assumption is not correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM