1. 程式人生 > >JS判斷客戶端型別(含微信)

JS判斷客戶端型別(含微信)

由於DOM物件是從上到下是順序載入的,使用時請放在body內下方處。

<script type="text/javascript">
    window.onload = browserRedirect();
    function browserRedirect() {//判斷客戶端型別
var sUserAgent = navigator.userAgent.toLowerCase();
        var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
        var bIsIphoneOs = sUserAgent.match
(/iphone os/i) == "iphone os"; var bIsMidp = sUserAgent.match(/midp/i) == "midp"; var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4"; var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb"; var bIsAndroid = sUserAgent.match(/android/i) == "android"; var bIsCE = sUserAgent
.match(/windows ce/i) == "windows ce"; var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile"; var bIsWeChat = sUserAgent.match(/MicroMessenger/i) == "micromessenger";//微信端 if (bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM || bIsWeChat) { var
menu = document.getElementById("menu"); menu.style.display = "none"; } else { var menuMobile =document.getElementById("menuMobile"); menuMobile.style.display = "none"; } } </script>