用戶移動端訪問pc站時,自動跳轉到移動站點
- 分類:博文-IT資訊
- 發布于 2016年5月06日 星期五 22:42
- 作者:Super User
- 點擊數:6307
用js判斷當前瀏覽器的類型:navigator.userAgent ;然后跳轉到手機網站路徑實現:
<script?type="text/javascript">
//?JavaScript?Document
function?urlredirect()?{
????var?sUserAgent?=?navigator.userAgent.toLowerCase();?
????if?((sUserAgent.match(/(ipod|iphone?os|midp|ucweb|android|windows?ce|windows?mobile)/i)))?{
????????//?PC跳轉移動端
????????var?thisUrl?=?window.location.href;
????????window.location.href?=?thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'mobile/';?//跳轉為網址后面加mobile的路徑,如:www.muhammadmuhdtaib.com/mobile
?????????
????}
}
urlredirect();
</script>