Hello list,

in the past few days I have stumbled across a problem in determining the 
Internet Explorer version from the user agent string
when Internet Explorer decides to use compatibility mode. In this case IE11 is 
considered to be IE7 for example, which is a
big problem in my case.

More precisely, I have two different problems concerning compatibility mode 
issues which I urgently must take care of. For a
quick solution I could mot see another option but to make some modifications to 
the code of Wt 3.3.2 (see below for details).

I would like to know if the modifications mentioned below can be done without 
further problems or if I am missing something
important. Maybe there already is a much more clean way in Wt 3.3.2 to achieve 
the same behaviour, but without making changes
in the code, or perhaps there is in Wt 3.3.3?

Thank you in advance and all the best,

Marc Faber





1. Detecting IE version from "MSIE" information first, "Trident" comes second
=============================================================================

In WEnvironment::setUserAgent(), the user agent string is searched for "MSIE" 
followed by the version number when it comes to
detecting the IE version. If finding this information is not successful, a 
second search is done for the "Trident" version.

With Internet Explorer using compatibility mode, however, the user agent string 
can look pretty much like this:

   Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.3; Trident/7.0; .NET4.0E; 
.NET4.0C)


The browser is defined as IE7 then, although IE11 would be suitable. This can 
cause many different problems, as it does
in my case (for example, IE uses compatibility mode for intranet addresses as a 
standard).

Since I needed a quick solution for this, I modified the detection of the user 
agent in WEnvironment::setUserAgent() so that
looking for the Trident information is the first step and "MSIE" (for IE7 and 
newer ones) comes second. After some testing I
can say that it does exactly what I need here:


WEnvironment::setUserAgent(), original:
---------------------------------------

   if (userAgent_.find("MSIE 2.") != std::string::npos
       || userAgent_.find("MSIE 3.") != std::string::npos
       || userAgent_.find("MSIE 4.") != std::string::npos
       || userAgent_.find("MSIE 5.") != std::string::npos
       || userAgent_.find("IEMobile") != std::string::npos)
     agent_ = IEMobile;
   else if (userAgent_.find("MSIE 6.") != std::string::npos)
     agent_ = IE6;
   else if (userAgent_.find("MSIE 7.") != std::string::npos)
     agent_ = IE7;
   else if (userAgent_.find("MSIE 8.") != std::string::npos)
     agent_ = IE8;
   else if (userAgent_.find("MSIE 9.") != std::string::npos)
     agent_ = IE9;
   else if (userAgent_.find("MSIE") != std::string::npos)
     agent_ = IE10;
   else if (userAgent_.find("Trident/5.0") != std::string::npos) {
     agent_ = IE9; return;
   } else if (userAgent_.find("Trident/6.0") != std::string::npos) {
     agent_ = IE10; return;
   } else if (userAgent_.find("Trident/") != std::string::npos) {
     agent_ = IE11; return;
   }


WEnvironment::setUserAgent(), modified:
---------------------------------------

   if (userAgent_.find("MSIE 2.") != std::string::npos
       || userAgent_.find("MSIE 3.") != std::string::npos
       || userAgent_.find("MSIE 4.") != std::string::npos
       || userAgent_.find("MSIE 5.") != std::string::npos
       || userAgent_.find("IEMobile") != std::string::npos)
     agent_ = IEMobile;
   else if (userAgent_.find("Trident/4.0") != std::string::npos)
     agent_ = IE8;
   else if (userAgent_.find("Trident/5.0") != std::string::npos)
     agent_ = IE9;
   else if (userAgent_.find("Trident/6.0") != std::string::npos)
     agent_ = IE10;
   else if (userAgent_.find("Trident/") != std::string::npos)
     agent_ = IE11;
   else if (userAgent_.find("MSIE 6.") != std::string::npos)
     agent_ = IE6;
   else if (userAgent_.find("MSIE 7.") != std::string::npos)
     agent_ = IE7;
   else if (userAgent_.find("MSIE 8.") != std::string::npos)
     agent_ = IE8;
   else if (userAgent_.find("MSIE 9.") != std::string::npos)
     agent_ = IE9;
   else if (userAgent_.find("MSIE") != std::string::npos)
     agent_ = IE10;





2. Setting the UA Compatibility meta tag for IE8 as well
========================================================

When using IE9, the following tag is set by the Wt application:

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


Appropriate tags are also set for IE10 and IE11, but unfortunately it is not 
done for IE8. In that case, it appears to me the
browser also falls back to compatibility mode, and thus to IE7 behaviour. I 
could not figure out a way to make that IE8 tag appear
as by modifying two other blocks of code. Concerning some testing I have done 
today, this works perfect for my needs:


WebRenderer::headDeclarations(), original:
------------------------------------------

   const Configuration& conf = session_.env().server()->configuration(); 
   bool selectIE7 = conf.uaCompatible().find("IE8=IE7")
     != std::string::npos;

   if (selectIE7) {
     result << "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=7\"";
     closeSpecial(result);
   }


WebRenderer::headDeclarations(), modified:
------------------------------------------

   const Configuration& conf = session_.env().server()->configuration(); 
   bool selectIE7 = conf.uaCompatible().find("IE8=IE7") != std::string::npos;

   if (selectIE7) {
     result << "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=7\"";
     closeSpecial(result);
   } else if (session_.env().agent() == WEnvironment::IE8) {
     result << "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\"";
     closeSpecial(result);
   }


WApplication::WApplication(), original:
---------------------------------------

   const Configuration& conf = environment().server()->configuration(); 
   bool selectIE7 = conf.uaCompatible().find("IE8=IE7")
     != std::string::npos;

   if (selectIE7)
     addMetaHeader(MetaHttpHeader, "X-UA-Compatible", "IE=7");


WApplication::WApplication(), modified:
---------------------------------------

   const Configuration& conf = environment().server()->configuration(); 
   bool selectIE7 = conf.uaCompatible().find("IE8=IE7") != std::string::npos;

   if (selectIE7) {
     addMetaHeader(MetaHttpHeader, "X-UA-Compatible", "IE=7");
   } else if (environment().agent() == WEnvironment::IE8) {
     addMetaHeader(MetaHttpHeader, "X-UA-Compatible", "IE=8");
   }

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their 
applications. Written by three acclaimed leaders in the field, 
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/NeoTech
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to