Home  >  Article  >  Web Front-end  >  JS script jumps to WAP mobile website according to mobile browser type (two methods)_javascript skills

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

WBOY
WBOYOriginal
2016-05-16 15:47:251382browse

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>

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

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:

c18ce45ef01a6dc6bbf42431abf519cb2cacc6d41bbb37262a98f745aa00fbf0
4ec11beb6c39d0703d1751d203c17053uaredirect("http://www.laozuo.org (replace with your own WAP website)");2cacc6d41bbb37262a98f745aa00fbf0

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.

Statement:
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