My web site want to be open IE7 and above .If IE 6 ,I want to produce warning and free download other browser icons .Is it possible?
views:
878answers:
5You can check the $_SERVER['HTTP_USER_AGENT']
variable for IE.
if (eregi("MSIE", $_SERVER["HTTP_USER_AGENT"]) ||
eregi("Internet Explorer", $_SERVER["HTTP_USER_AGENT"])) {
// IE
}
You can get some examples that don't require server side scripting from ie6nomore.com.
They use the conditional comments feature of IE, like this:
<!--[if lt IE 7]>
Your browser is outdated!
<![endif]-->
But the examples on the site actually offer links to other browsers. Of course, you can roll your own version that suits your layout better.
Of course, you can do this server side if you prefer, since you're using PHP anyway. The other examples here using $_SERVER["HTTP_USER_AGENT"]
should get you started. Using get_browser
may be overkill, as it requires a fairly large data file to function.
If you're only interested in detecting old IE versions server side, this should do:
preg_match('/; MSIE (\d+.\d+)/', $_SERVER['HTTP_USER_AGENT'], $matches);
if (count($matches) > 1 && $matches[1] <= 6.0)
{
echo "Your browser is outdated";
}
Use IE conditional comments in your page
<!--[if lt IE 7]>
include a warning here (in an iframe, perhaps, to save extra bandwidth)
<![endif]-->
You should be able to do so easily by using the built-in get_browser
function.
In case you wish to see what the output looks like if visited by IE 6, you can grab a user agent string from UserAgentString.com to test it out.
Alternatively you could also check it with a JavaScript
/*
* Check whether the current browser is IE6
*/
function isBrowserIE6() {
if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) {
return true;
} else {
return false;
}
}
(The above would just work in a ASP.net environment. Here's a blog post which handles IE browser checking the native way).
You then add an HTML container element on your page
<div id="ie6BrowserWarning" style="display:none">
Your browser is outdated. Please download one of the alternative browsers!
<!-- Set of links to Firefox, Chrome, Safari, Opera,... -->
</div>
And on page load you do
<html>
<head>
<script type="text/javascript">
function doIE6WarningCheck()
{
var element = document.getElementById("ie6BrowserWarning");
var isIE6 = isBrowserIE6();
if(element != null && isIE6 == true)
{
element.style.display = "block";
}
}
</script>
</head>
<body onLoad="doIE6WarningCheck()">
<div id="ie6BrowserWarning" style="display:none">
Your browser is outdated. Please download one of the alternative browsers!
<!-- Set of links to Firefox, Chrome, Safari, Opera,... -->
</div>
</body>
</html>
I didn't check that, just wrote it out of my head right now. You'd have to do that, but I guess it should work. Firebug is always a good option for JavaScript debugging.