Two JS script to judge Mobile browser type jump WAP mobile phone site _javascript Tips

Source: Internet
Author: User
Tags hash

With the popularization of mobile devices, the enterprise's network propaganda can not be limited to the PC side, but also need to contribute to the mobile end of the achievements. For the company's website, the previous is done by the PC side, of course, mobile phones and other mobile end can also access, but the user experience is certainly not as good as the full fit of the phone to the convenience. We have done to their own website WAP Mobile website, if there are users through the mobile phone to visit our corporate top-level domain Web site, it will be judged to jump to a dedicated WAP site.
Here old left collation to the current oneself in the use of 2 of JS script, because there have been friends with me, so here to share it out.

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)/i))
{
window.location= "http://www.laozuo.org (replace to own WAP web site)";
}} catch (Err)
{

The second type, 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.

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

After my test two JS script can be judged mobile browser type to jump WAP mobile phone site, the need for friends to take the past use directly.

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.