Home > Web Front-end > JS Tutorial > body text

JS script jumps to WAP mobile website according to mobile browser type (two methods)_javascript skills

WBOY
Release: 2016-05-16 15:47:25
Original
1426 people have browsed it

With the continuous popularity of mobile Internet, corporate online promotion is not only limited to the PC side, but also develops on the mobile side. After we complete the WAP mobile phone on our own website, if a user accesses our corporate top-level domain name website through a mobile phone, we must judge and jump to the WAP website specially designed for it. The editor below introduces two methods according to the mobile browser type. Jump to the WAP mobile website, the specific content is as follows.

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(更换成自己的WAP网站)";
}
}
}
catch(err)
{
}</script>
Copy after login

The second way, slightly longer, is to quote


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){}
}
Copy after login

Save the above script to the mobile.js file, and then reference the following 2 JS call files on the page that needs to be called.

Copy code The code is as follows:




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

The above is the entire content of jumping to the WAP mobile website according to the mobile browser type through two methods. I hope you like it.

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template