隨著移動設(shè)備的普及,企業(yè)的網(wǎng)絡(luò)宣傳已經(jīng)不能局限在PC端,而需要同時在移動端有所建樹。對于公司網(wǎng)站來說,以前都是做的PC端的,當然手機等移動端也可以訪問,但是用戶體驗肯定不如完全適合的手機端來的方便。我們在給自己的網(wǎng)站做了WAP手機網(wǎng)站之后,如果有用戶通過手機訪問我們的企業(yè)頂級域名網(wǎng)站,那就判斷跳轉(zhuǎn)到專為的WAP網(wǎng)站。
這里老左整理到目前自己在使用的2種JS腳本,因為之前一直有朋友跟我要,所以這里分享出來。
第一種:直接JS腳本
<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://www.laozuo.org(更換成自己的WAP網(wǎng)站)";}}}catch(err){}</script> 第二種,稍微長一些,引用
function uaredirect(murl){try {if(document.getElementById("bdmark") != null){return;}var urlhash = window.location.hash;if (!urlhash.match("fromapp")){if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {location.replace(murl);}}} catch(err){}}上述的腳本保持到mobile.js文件,然后在需要調(diào)用的頁面引用下面2個JS調(diào)用文件。
<script src="mobile.js" type="text/javascript"></script><script type="text/javascript">uaredirect("http://www.laozuo.org(更換成自己的WAP網(wǎng)站)");</script>經(jīng)本人測試兩款js腳本均可判斷手機瀏覽器類型跳轉(zhuǎn)WAP手機網(wǎng)站,需要的朋友直接拿過去用。
新聞熱點
疑難解答