2 JS script to determine mobile browser jump WAP Mobile website

Source: Internet
Author: User

With the popularization of mobile devices, the enterprise's network propaganda can not be limited to the PC side, but also need to build on the mobile side. For the company's website, used to do the PC-side, of course mobile phones and other mobile terminals can also be accessed, but the user experience is certainly not as fully suitable for the convenience of the mobile phone. After we have made a WAP mobile website for our website, if there is a user to visit our Enterprise top-level domain website through mobile phone, then judge jump to the WAP website dedicated to it.

Here to organize the 2 kinds of JS scripts that are currently in use, because there have been friends with me before, so here to share.

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)))
{
Window.location= "http://www.laozuo.org (change to own WAP website)";
}
}
}
catch (Err)
{
}</script>

The second kind, a little longer, references

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))) {
Location.replace (Murl);
}
}
} catch (Err) {}
}

The above script is persisted to the Mobile.js file, and then the following 2 JS call files are referenced in the page that needs to be called.

<script src= "Mobile.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >uaredirect ("http://www.laozuo.org (change to own WAP website)");</script>

Both methods can be used, and my test on Android and iphone is feasible.

2 JS script to determine mobile browser jump WAP Mobile website

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.