I'm intending to place some code into the header of my CMS that will alert any users who are using IE 8 and below, suggesting to upgrade their browser.
In PHP, I've got the following code, and it shows for ALL versions of IE.
<?php
if(preg_match('/(?i)msie [1-8]/',$_SERVER['HTTP_USER_AGENT'])) {
// if IE<=8
?>
<!--[if lte IE 8]>
<div class="ieNotice">
<a href="http://windows.microsoft.com/en-us/internet-explorer/" target="_blank">
<img src="/skin/frontend/default/hellowired/images/ieUpgrade.jpg">
</a>
</div>
<style>
.ieNotice {
background-color: #eee;
padding: 10px;
}
</style>
<![endif]-->
<?php
}
?>
This SHOULD work two fold. One, the $_SERVER['HTTP_USER_AGENT'])
should be able to tell the browsers apart. However, I'm noticing that when I run cross browser testing, IE 8 and UP are coming back with the same result for $_SERVER['HTTP_USER_AGENT'])
, which is:
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)
OK... even if that didn't work... wouldn't the "Quirks Mode" conditional comments be there as a fallback to only show the image and link to IE8 and below? What am I missing here?
EDIT
OK, so I have done as instructed. I have removed the PHP code, and placed the .ieNotice
class with the display: none
property. Now, on the stylesheet that is included here:
<!--[if lte IE 8]>
<link rel="stylesheet" type="text/css" href="/skin/frontend/default/hellowired/css/styles-ie-lte8.css" media="all" />
<![endif]-->
I have added the following line:
.ieNotice { display: block !important;}
I have seen this work on Firefox and Chrome properly, but it is still showing the banner I've created for IE 9, 10 & 11.