JS script to the mobile browser type to jump WAP mobile Web site (two ways) _javascript tips

Source: Internet
Author: User
Tags hash

With the continuous popularization of mobile Internet, Enterprise's network propaganda is not only limited to the PC side, but also to develop on the mobile end. We have done in their own website WAP mobile phone integrity, if there is a user through the mobile phone to our enterprise top-level domain name site, we must judge to jump to a dedicated WAP site, the following small series through two ways according to mobile phone browser type jump WAP mobile phone site, the specific content below.

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 (replace to own WAP web site)";
}} catch (Err)
{
}</script>

The second way, 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)/i))) {
location.replace (murl);
} \
catch (Err) {}
}}

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

Copy Code code as follows:

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

Both methods are available, and I am able to test Android and iphone.

The above is through two ways to achieve according to mobile phone browser type to jump WAP mobile phone site All the content, I hope you like.

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.