//判断浏览器类型
private function getBrowser() {
$sys = $_SERVER['HTTP_USER_AGENT'];
if (stripos($sys, "Firefox/") > 0) {
preg_match("/Firefox\/([^;)]+)+/i", $sys, $b);
$exp[0] = "Mozilla Firefox";//火狐
$exp[1] = $b[1];
} elseif (stripos($sys, "Chrome") > 0) {
$exp[0] = "Chrome";//谷歌
$exp[1] = "";
} elseif (stripos($sys, "MSIE") > 0) {
preg_match("/MSIE\s+([^;)]+)+/i", $sys, $ie);
//$exp = "Internet Explorer ".$ie[1];
$exp[0] = "Internet Explorer";//IE
$exp[1] = $ie[1];
} elseif (stripos($sys, "Edge") > 0) {
$exp[0] = "Edge";//微软Edge
$exp[1] = "";
} elseif (stripos($sys, "Opera") > 0) {
$exp[0] = "Opera";
$exp[1] = "";
} else {
$exp = "未知浏览器";
$exp[1] = "";
}
return $exp;
}
//调用
$exp = $this->getBrowser();//获取浏览器版本、版本号
$this->assign('version', $exp[0]);
$this->assign('number', $exp[1]);
js
<script type="text/javascript">
var version = "{$version}";
var number = "{$number}";
if(version === 'Internet Explorer' && number < 10){
alert('您的浏览器版本过低,为了您更好的浏览体验,请使用IE10内核以上版本浏览器。');
exit;
}
</script>
//判断手机型号 iOS或android
<script type="text/javascript">
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
var url = '';
$(".open").click(function () {
if (isAndroid == true) {
alert('android');
} else if (isiOS == true) {
alert('iOS');
}
window.open(url);
});
</script>