New problem, IE8 capability on java sites

By support at augusti 05, 2009 21:07
Filed Under:

I have a customer with quite a few java sites that were not built for IE8.. well how could they it is pretty new.

And changing them is a costly affair that their customers in turn might be reluctant to do.

 

What I did was make a java filter, now I am in no way a java expert so feel free to tell me if I did anything strange :)

 

  1: public class IE8Filter implements Filter {
  2:     private FilterConfig fConfig = null;
  3: 
  4:     public void init(FilterConfig filterConfig) throws ServletException {
  5:         this.fConfig = filterConfig;
  6: 
  7:     }
  8: 
  9:     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
 10:         String unparsedMode = fConfig.getInitParameter("CompabilityMode");
 11:         String strXUA= "IE=EmulateIE7";
 12:         if ((unparsedMode == "5") || (unparsedMode == "IE5")){
 13:             strXUA = "IE=5";
 14:         } else if ((unparsedMode == "7") || (unparsedMode == "IE7")){
 15:             strXUA = "IE=7";
 16:         } else if ((unparsedMode == "8") || (unparsedMode == "IE8")){
 17:             strXUA = "IE=8";
 18:         } else if (unparsedMode == "EmulateIE7"){
 19:             strXUA = "IE=EmulateIE7";
 20:         } else if (unparsedMode == "EmulateIE8"){
 21:             strXUA = "IE=EmulateIE8";
 22:         } else if (unparsedMode == "Edge"){
 23:             strXUA = "IE=Edge";
 24:         }
 25: 
 26:         ((HttpServletResponse) response).setHeader("X-UA-Compatible", strXUA);
 27:         chain.doFilter(request, response);
 28:     }
 29: 
 30:     public void destroy() {
 31:     }
 32: }

 

With the code above you can now add the configuration too your web.xml

  1:     <filter>
  2:      <filter-name>IE8Filter</filter-name>
  3:      <filter-class>PackageName.IE8Filter</filter-class>
  4:      <init-param>
  5:       <param-name>CompabilityMode</param-name>
  6:       <param-value>7</param-value>
  7:      </init-param>
  8:     </filter>
  9: 
 10:   <filter-mapping>
 11:     <filter-name>IE8Filter</filter-name>
 12:     <url-pattern>/*</url-pattern>
 13:   </filter-mapping>

With the above you would use the capability mode for IE7, your options here are as follow.

Parameters
==========
(Descriptive text is from Microsoft)

<param-value>5</param-value>
IE5 mode renders content as if it were displayed by the Windows Internet Explorer 7 Quirks mode, which is very similar to how Microsoft Internet Explorer 5 displayed content.

<param-value>7</param-value>
IE7 mode renders content as if it were displayed by the Internet Explorer 7 Standards mode, whether or not the page contains a <!DOCTYPE> directive.

<param-value>EmulateIE7</param-value>
EmulateIE7 mode tells Windows Internet Explorer to use the <!DOCTYPE> directive to determine how to render content. Standards mode directives are displayed in Internet Explorer 7 Standards mode, and Quirks mode directives are displayed in IE5 mode. Unlike IE7 mode, EmulateIE7 mode respects the <!DOCTYPE> directive. For many Web sites, this is the preferred compatibility mode.

<param-value>EmulateIE8</param-value>
EmulateIE8 mode is similar to EmulateIE7 mode; Internet Explorer uses the <!DOCTYPE> directive to determine how to render content; however, standards mode directives are displayed in Internet Explorer 8 Standards mode. Quirks mode directives are displayed in IE5 mode.

<param-value>8</param-value>
IE8 mode provides the highest support available for industry standards, including the W3C Cascading Style Sheets Level 2.1 Specification and the W3C Selectors API, as well as limited support for the W3C Cascading Style Sheets Level 3 Specification (Working Draft).

<param-value>Edge</param-value>
Edge mode tells Windows Internet Explorer to display content in the highest mode available, which actually breaks the “lock-in” paradigm. With Internet Explorer 8, this is equivalent to IE8 mode. If a (hypothetical) future release of Internet Explorer supported a higher compatibility mode, pages set to Edge mode would appear in the highest mode supported by that version; however, those same pages would still appear in IE8 mode when viewed with Internet Explorer 8. It is recommended that Web developers restrict their use of Edge mode to test pages and other non-production uses because of the possible unexpected results of rendering page content in future versions of Windows Internet Explorer.

 

Below is a link to the jar library and the readme on how to use. The company I wrote it for is a freesource company and would give access to code I think, but you will have to write me if you want the entire code.

Kommentarer