例1。欠落ポイントのシンプルで粗野な判断
<script type = "text/javascript"> var suseragent = navigator.useragent.tolowercase(); var bisipad = suseragent.match(/ipad/i)== "iPad"; var bisiphoneos = suseragent.match(/ii)== "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"; if(bisipad || bisiphoneos || bismidp || bisuc7 || bisuc || bisandroid || bisce || biswm){window.location.href = "3g.php"; } </script>例2:コードはきれいで、多くの関数はこの追加機能に基づいています。
<script> var pc_style = "" var browser = {versions:function(){var u = navigator.useragent、app = navigator.appversion; return {trident:u.indexof( 'trident')> -1、presto:u.indexof( 'presto')> -1、webkit:u.indexof( 'applewebkit') u.indexof( 'gecko')> -1 && u.indexof( 'khtml')== -1、mobile:!! u.match(/applewebkit.*mobile。*/)|| !! U.Match(/AppleWebkit/)&& U.Indexof( 'Qihu')&& U.indexof( 'Qihu')> -1 && u.indexof( 'Chrome')<0、iOS:!! U.Match(//(I [^;]+;(u;)? u.indexof( 'linux')> -1、iPhone:u.indexof( 'iPhone')> -1 ||。 navigator.language).tolowercase()} if(browser.versions.mobile &&!browser.versions.ipad){this.location = "ジャンプマイクロステーションのホームページアドレスを入力してください";} </script>例3:いくつかの関数が追加されています
<! - スマートフォンの判断開始 - > <! - <スクリプトタイプ= "text/javascript"言語= "javascript"> function.prototype.bind = function(bindobj、args){var _ self = this; return function(){return _self.apply(bindobj、[] .concat)} document.getElementById(id):id;}; var browser = {versions:function(){var u = navigator.useragent、app = navigator.appversion; return {trident:u.indexof( 'trident')> -1、presto:u.indexof( 'presto') u.indexof( 'gecko')> -1 && u.indexof( 'khtml')== -1、mobile:!! u.match(/applewebkit.*mobile。*/)|| !! u.match(/applewebkit/)、ios:!! u.match(//(i [^;]+;(u;)?cpu。+mac os x/)、android:u.indexof( 'android')> || u.indexof( 'linux')> -1、iPhone ') U.indexof( 'iPad')> -1、webApp:u.indexof( 'safari')== -1、qqbrw:u.indexof( 'mqqbrowser') Parsefloat(U.Match(/ucweb/d+/。/d+/gi).toString()。match(// d+/。/d+/)。toString())> = 8.2} catch(e){if(u.indexof( 'uc')> -1){return true;} x return {return true;) U.indexof( 'Symbian')> -1、ucsb:u.indexof( 'firefox/1。')> -1};}()} var _gaq = _gaq || rf.tolocalelowercase()。indexof( "。xiu.com")=== -1){var defaultjumpdomain = ""; if(defaultjumpdomain == "www"){return;} if(defaultjumpdomain == "m"){window.location.href = " == undefined ||。 browser.versions.ucspecial == true){win.location.href = "http://wap.xiu.com/?from=pc"; return;} f(browser.versions.symbian){win.location.href =" http://wap.xiu.com/ </script> - > <! - スマートフォンの判断の終了 - >例4:単純なwulin.comを使用することをお勧めします。より良いコードがある場合は、共有できます。
<script type = "text/javascript"> var browser = {versions:function(){var u = navigator.useragent、app = navigator.appversion; return {trident:u.indexof( 'trident')> -1、presto:u.indexof( 'presto')> -1、webkit:u.indexof:applewebkit ') u.indexof( 'gecko')> -1 && u.indexof( 'khtml')== -1、mobile:!! u.match(/applewebkit.*mobile。*/)|| !! u.match(/applewebkit/)、ios:!! u.match(//(i [^;]+;(u;)?cpu。+mac os x/)、android:u.indexof( 'android')> || u.indexof( 'linux')> -1、iPhone ') U.indexof( 'iPad')> -1、webApp:U.indexof( 'safari')== -1、qqbrw:u.indexof( 'mqqbrowser') U.indexof( 'rv:1.2.3.4')> -1、ucweb:function(){try {return parsefloat(/ucweb/d+/。/d+/gi).tostring()。マッチ(// d+//。/d+/)。 {return true;} else {return false;}}()、symbian:u.indexof( 'symbian')> -1、ucsb:u.indexof( 'firefox/1。')> -1};}()、liulanqi:navigator.useragent} i browser ");} else {document.write(" other browser "+browser.liulanqi);} </script>