手機訪問pc網站自動跳轉手機端網站代碼

來源:互聯網
上載者:User

標籤:

<script>
alert(navigator.platform) ; 擷取服務端裝置!
</script>

備忘這裡的mobile_device_detect("http://***.***.com");//裡面的地址填的就是您的移動端的網站地址呦。<SCRIPT LANGUAGE="JavaScript">function mobile_device_detect(url){ var thisOS=navigator.platform; var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile"); for(var i=0;i<os.length;i++) { if(thisOS.match(os[i])) { window.location=url; } } //因為相當部分的手機系統不知道資訊,這裡是做臨時性特殊辨認 if(navigator.platform.indexOf(‘iPad‘) != -1) { window.location=url; } //做這一部分是因為Android手機的核心也是Linux //但是navigator.platform顯示資訊不盡相同情況繁多,因此從瀏覽器下手,即用navigator.appVersion資訊做判斷 var check = navigator.appVersion; if( check.match(/linux/i) ) { //X11是UC瀏覽器的平台 ,如果有其他特殊瀏覽器也可以附加上條件 if(check.match(/mobile/i) || check.match(/X11/i)) { window.location=url; } } //類in_array函數 Array.prototype.in_array = function(e) { for(i=0;i<this.length;i++) { if(this[i] == e) return true; } return false; }} mobile_device_detect("http://***.***.com");</SCRIPT>

 

手機訪問pc網站自動跳轉手機端網站代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.