Two JS scripts determine the mobile browser type to jump to the WAP mobile website, jswap

Source: Internet
Author: User

Two JS scripts determine the mobile browser type to jump to the WAP mobile website, jswap

With the popularization of mobile devices, the network promotion of enterprises cannot be confined to PCs, but must be achieved at the same time on mobile terminals. For the company's website, it used to be a PC-end. Of course, mobile phones and other mobile terminals can also be accessed. However, the user experience is certainly not as convenient as that of mobile phones. After we create a WAP mobile website for our website, if a user accesses our enterprise top-level domain name website through a mobile phone, the user will jump to the specially designed WAP website.
Here, I have sorted out the two types of JS scripts that I am currently using, because I have been asking for them, so I will share them here.

First: Direct JS scripts

<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 (change to your own WAP website)" ;}} catch (err) {}</script>

Second, a little longer, reference

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

The above scripts are kept in 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 (" http://www.laozuo.org (change to your own WAP site )"); </script>

After testing two js scripts, you can determine the type of the mobile browser to jump to the WAP mobile website. If you need them, you can use them directly.

Related Article

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.