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

Two JS scripts determine the mobile browser type and jump to the WAP mobile website_javascript skills

WBOY
Release: 2016-05-16 15:36:26
Original
1801 people have browsed it

With the popularity of mobile devices, corporate online promotions can no longer be limited to the PC side, but need to make achievements on the mobile side at the same time. For company websites, they used to be made on PC. Of course, mobile terminals such as mobile phones can also be accessed, but the user experience is definitely not as convenient as a completely suitable mobile terminal. After we build a WAP mobile website for our website, if a user accesses our corporate top-level domain name website through a mobile phone, we will jump to the specially designed WAP website.
Here, Lao Zuo has sorted out two JS scripts that he is currently using. Because friends have been asking me for them before, I share them here.

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

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

<script src="mobile.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("http://www.laozuo.org(更换成自己的WAP网站)");</script>
Copy after login

After testing by myself, both js scripts can determine the mobile browser type and jump to the WAP mobile website. Friends who need it can use it directly.

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!