使用PHP
?0
<?php
if(isset($_SERVER['HTTP_USER_AGENT'])){
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strlen(strstr($agent,"MSIE")) > 10){
echo "sorry: not compatible";
}}
?>
使用PHP(特定)
<?php
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
echo 'Internet explorer';
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE)
echo 'Mozilla Firefox';
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE)
echo 'Google Chrome';
else
echo 'Something else';
?>
用java腳本
<script type="text/javascript">
function getInternetExplorerVersion()
{
var rv = -1;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var ua = navigator.userAgent;
var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
if (re.exec(ua) != null)
rv = parseFloat(RegExp.$1);
}
return rv;
}
function checkVersion()
{
var msg = "You're not using Internet Explorer.";
var ver = getInternetExplorerVersion();
if (ver > -1)
{
if (ver >= 8.0)
msg = "You're using a recent copy of Internet Explorer."
else
msg = "You should upgrade your copy of Internet Explorer.";
}
alert(msg);
}
</script>
如果(的preg_match('/(ⅰ)(MSIE [0-9] +)|(三叉戟/ [0-9] +)/',$ _ SERVER ['HTTP_USER_AGENT']))....這不起作用.... preg_match():未知修飾符'[' – Susanne92