代码如下:
function isWeiXin(){
var ua = window.navigator.userAgent.toLowerCase()
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
return true
}else{
return false
}
}
demo: 代码如下:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>判断是否是微信内置浏览器</title>
</head>
<body>
<h1>如果用微信浏览器打开可以看到下面的文字</h1>
<p></p>
</body>
</html>
<script type="text/javascript">
window.onload = function(){
if(isWeiXin()){
var p = document.getElementsByTagName('p')
p[0].innerHTML = window.navigator.userAgent
}
}
function isWeiXin(){
var ua = window.navigator.userAgent.toLowerCase()
if(ua.match(/MicroMessenger/i) == 'micromessenger'){
return true
}else{
return false
}
}
</script>.
if(navigator.userAgent.indexOf("MicroMessenger")>-1){alert("这是微信内置浏览器")
}else{
alert("这不是微信内置浏览器")
}