JS scripts jump to the WAP mobile Website Based on the mobile browser type (two methods), jswap

Source: Internet
Author: User

JS scripts jump to the WAP mobile Website Based on the mobile browser type (two methods), jswap

With the increasing popularity of the mobile Internet, enterprise network propaganda is not only limited to PC, but also to mobile development. After we complete our WAP mobile phone on our website, if a user accesses our enterprise top-level domain name website through a mobile phone, we need to determine that the website will jump to the specially designed WAP website, the following section describes how to jump to a WAP mobile Website Based on the mobile browser type in two ways. The specific content is as follows.
Method 1: 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>

The second method, which is a little longer and referenced


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.
Copy codeThe Code is as follows:
<Script src = "mobile. js" type = "text/javascript"> </script>
<Script type = "text/javascript"> uaredirect ("http://www.laozuo.org (change to your own WAP website)"); </script>

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

The above two methods are used to redirect all content to the WAP mobile Website Based on the mobile browser type.

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.