With the continuous popularization of mobile Internet, Enterprise's network propaganda is not only limited to the PC side, but also to develop on the mobile end. We have done in their own website WAP mobile phone integrity, if there is a user through the mobile phone to our enterprise top-level domain name site, we must judge to jump to a dedicated WAP site, the following small series through two ways according to mobile phone browser type jump WAP mobile phone site, the specific content below.
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 (replace to own WAP web site)";
}} catch (Err)
{
}</script>
The second way, 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.
Copy Code code as follows:
<script src= "Mobile.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >uaredirect ("http://www.laozuo.org (replace to own WAP site)");</script>
Both methods are available, and I am able to test Android and iphone.
The above is through two ways to achieve according to mobile phone browser type to jump WAP mobile phone site All the content, I hope you like.