Home > Article > Web Front-end > JS script jumps to WAP mobile website according to mobile browser type (two methods)_javascript skills
With the continuous popularity of mobile Internet, corporate online promotion is not only limited to the PC side, but also develops on the mobile side. After we complete the WAP mobile phone on our own website, if a user accesses our corporate top-level domain name website through a mobile phone, we must judge and jump to the WAP website specially designed for it. The editor below introduces two methods according to the mobile browser type. Jump to the WAP mobile website, the specific content is as follows.
The first way: direct JS script
<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网站)"; } } } catch(err) { }</script>
The second way, slightly longer, is to quote
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){} }
Save the above script to the mobile.js file, and then reference the following 2 JS call files on the page that needs to be called.
The above is the entire content of jumping to the WAP mobile website according to the mobile browser type through two methods. I hope you like it.