Two mobile browsers determine to jump to WAP website JS files

Source: Internet
Author: User
Tags hash
Here we only need to use a simple JS judgment to achieve the jump. The following two methods have been used by Lao Jiang before. If you need them, you can refer to adding them to the website.

 

First:

 

The code is as follows: Copy code

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

 

Save the above file to the shouji. js file and reference it in the website to be called.

 

The code is as follows: Copy code

<Script src = "shouji. js" type = "text/javascript"> </script>
<Script type = "text/javascript"> uaredirect ("http://www.itbulu.com/"); </script>

 

The red part is replaced with our WAP site.

 

Second:

 

The code is as follows: Copy code

<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.itbulu.com /";
}
}
}
Catch (err)
{
} </Script>

 

Directly add a JS file to the required page, and replace the URL with ours. This type can also be encapsulated in the JS file and called. It can be used to re-adjust some published site information. The first type is directly added to the site.

 

To sum up, the above two mobile browsers have been able to determine that the method for redirecting to the WAP website JS file has been tested. Generally, there is no problem.

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.