手机ç‰ç§»åŠ¨è®¾å¤‡è®¿é—®PC端站点自动跳转到手机网站的跳转代ç
ã€è·³è½¬ä»£ç 一】
XML/HTML代ç
- <script type="text/javascript">
- try {
- var urlhash = window.location.hash;
- if (!urlhash.match("fromapp"))
- {
- if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
- {
- window.location="http://m.your-website.com/"; //这里的网å€è¯·æ”¹ä¸ºä½ 手机站的网å€
- }
- }
- }
- catch(err)
- {
- }
- </script>
ã€è·³è½¬ä»£ç 二】(利用百度Site App代ç 判æ–手机访问)
XML/HTML代ç
- <script language="JavaScript">function uaredirect(f){try{if(document.getElementById("bdmark")!=null){return}var b=false;if(arguments[1]){var e=window.location.host;var a=window.location.href;if(isSubdomain(arguments[1],e)==1){ff=f+"/#m/"+a;b=true}else{if(isSubdomain(arguments[1],e)==2){ff=f+"/#m/"+a;b=true}else{f=a;b=false}}}else{b=true}if(b){var c=window.location.hash;if(!c.match("fromapp")){if((navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i))){location.replace(f)}}}}catch(d){}}function isSubdomain(c,d){this.getdomain=function(f){var e=f.indexOf("://");if(e>0){var h=f.substr(e+3)}else{var h=f}var g=/^www\./;if(g.test(h)){hh=h.substr(4)}return h};if(c==d){return 1}else{var c=this.getdomain(c);var b=this.getdomain(d);if(c==b){return 1}else{cc=c.replace(".","\\.");var a=new RegExp("\\."+c+"$");if(b.match(a)){return 2}else{return 0}}}};uaredirect("m.your-website.com");</script>
- <script type="text/javascript">uaredirect("m.your-website.com");</script>​
ã€è·³è½¬ä»£ç 三】
XML/HTML代ç
- <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://m.your-website.com");
- </script>
æŠ€èƒ½åˆ¶é€ å¤§å¸ˆ
2019/04/26 20:09
å¥½æ–‡ç« ï¼Œå¥½å¥½å¦ä¹ ,天天å‘上,支æŒä¸€ä¸‹
文娱å¸å›½
2019/03/30 19:32
写的很好,很喜欢
丘八
2019/02/26 19:16
æ–‡ç« ä¸é”™,éžå¸¸å–œæ¬¢
分页: 1/1 1