Some times it might happen that an older website is not working properly in Internet Explorer 10. For example the jQuery popups are not opening but working in previous version of IE.
The reason behind it can be that the website contains doctype as <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>, html tags are not correct or not as per HTML5 specifications and others which all together some how compatible till IE 9 but not in IE 10.
IE 10 will show an error as Invalid DOCTYPE. The shortest valid doctype is “<!DOCTYPE html>”
which can lead to several unexpected side-effects if you’re unfamiliar with the directive.
And it very difficult to change the doc type as <!DOCTYPE html> or change the entire website code structure to make it compatible with IE 10 which may not also work in IE 10 or can even break the site in older version too.
This issue can simply be fixed by using the below code in head tag.
<meta http-equiv="X-UA-Compatible" content="IE=5" /> where content='the_ie_version_your_site_is_compatible_with'. the possible values are "IE=5" "IE=EmulateIE7" "IE=7" "IE=EmulateIE8" "IE=8" "IE=EmulateIE9" "IE=9" "IE=edge"
If there is a need to include the above meta tag only if the browser is IE 10 then it require to check the version of IE.
Condition comments are used to check browser version to include the html tag, run javascripts etc but it is supported till IE 9.
IE 10 and higher no longer supports conditional comments.
So in PHP the below code can be used to check the IE 10 and higher to include the meta tag.
Include the below code inside <head> tag.
<?php preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches); if ( (int)$matches[1] >= 10 ) { ?> <meta http-equiv="X-UA-Compatible" content="IE=5" /> <?php } ?>
Other ways of identifying the IE browser version:
PHP:
<?php preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $browserVersion); echo $browserVersion;
Jquery:
if ($.browser.msie && $.browser.version == 10) { //code } ?>
Javascript:
var ieVersion = /*@cc_on (function() { switch(@_jscript_version) { case 1.0: return 3; case 3.0: return 4; case 5.0: return 5; case 5.1: return 5; case 5.5: return 5.5; case 5.6: return 6; case 5.7: return 7; case 5.8: return 8; case 9: return 9; case 10: return 10; } })() || @*/ 0;
HTML:(It works till ie9 as IE 10 and higher no longer supports conditional comments.)
<!--[if IE 6]> <link rel="stylesheet" type="text/css" media="screen" href="ie6.css" /> < ![endif]--> <!--[if IE 7]> <link rel="stylesheet" type="text/css" media="screen" href="ie7.css" /> < ![endif]-->