Focus on cloud service provider activities
Notes on website operation and maintenance

Two JS scripts judge that mobile browsers jump to WAP mobile websites

With the popularization of mobile devices, the network publicity of enterprises can no longer be limited to the PC side, but needs to build on the mobile side at the same time. For the company website, it used to be on the PC side. Of course, mobile terminals such as mobile phones can also access it, but the user experience is certainly not as convenient as the completely suitable mobile terminal. After we have built a WAP mobile website for our website, if a user visits our corporate TLD website through mobile phone, then we will judge to jump to the dedicated WAP website.

Here, Lao Zuo has sorted out the two JS scripts he is currently using. I have been asked by friends before, so I share them here.

The first type: 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=" https://www.laozuo.org (Change to your own WAP website) ";
}
}
}
catch(err)
{
}</script>

The second one is slightly longer

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){}
}

Keep the above script to the mobile.js file, and then reference the following two JS call files on the page to be called.

<script src="mobile.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect(" https://www.laozuo.org (Change to your own WAP website) ");</script>

Both methods can be used. I can test them on Android and IPHONE.

Vote for you
Domain name host preferential information push QQ group: six hundred and twenty-seven million seven hundred and seventy-five thousand four hundred and seventy-seven Get preferential promotion from merchants.
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Two JS scripts judge that mobile browsers jump to WAP mobile websites