JavaScript
<script type="text/javascript">
var isIE = navigator.userAgent.search("MSIE") > -1;
var isIE7 = navigator.userAgent.search("MSIE 7") > -1;
var isFirefox = navigator.userAgent.search("Firefox") > -1;
var isOpera = navigator.userAgent.search("Opera") > -1;
var isSafari = navigator.userAgent.search("Safari") > -1;//Google瀏覽器是用這核心
if (isIE7) {
alert('isIE7');
}
if (isIE) {
alert('isIE');
}
if (isFirefox) {
alert('isFirefox');
}
if (isOpera) {
alert('isOpera');
}
if (isSafari) {
alert('isSafari or Chrome');
}
</script>
CSS
.classname{
background:blue; /*Firefox等非IE瀏覽器背景變藍色*/
background:red \9; /*IE8 背景變紅色*/
*background:black; /*IE7 背景變黑色*/
_background:orange; /*IE6 背景變橘色*/
}
PHP
//偵測瀏覽器
$agent = $_SERVER['HTTP_USER_AGENT'];
if(strpos($agent,"MSIE 8.0"))
echo "Internet Explorer 8.0";
else if(strpos($agent,"MSIE 7.0"))
echo "Internet Explorer 7.0";
else if(strpos($agent,"MSIE 6.0"))
echo "Internet Explorer 6.0";
else if(strpos($agent,"Firefox/3"))
echo "Firefox 3";
else if(strpos($agent,"Firefox/2"))
echo "Firefox 2";
else if(strpos($agent,"Chrome"))
echo "Google Chrome";
else if(strpos($agent,"Safari"))
echo "Safari";
else if(strpos($agent,"Opera"))
echo "Opera";
else
echo $agent;
文章參考:http://ithelp.ithome.com.tw/question/10095184
沒有留言:
張貼留言