JS scripts jump to the WAP mobile Website Based on the mobile browser type (two methods), jswap
With the increasing popularity of the mobile Internet, enterprise network propaganda is not only limited to PC, but also to mobile development. After we complete our WAP mobile phone on our website, if a user accesses our enterprise top-level domain name website through a mobile phone, we need to determine that the website will jump to the specially designed WAP website, the following section describes how to jump to a WAP mobile Website Based on the mobile browser type in two ways. The specific content is as follows.
Method 1: Direct JS scripts
<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 (change to your own WAP website)" ;}} catch (err) {}</script>
The second method, which is a little longer and referenced
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 scripts are kept in the mobile. js file, and then reference the following two JS call files on the page to be called.
Copy codeThe Code is as follows:
<Script src = "mobile. js" type = "text/javascript"> </script>
<Script type = "text/javascript"> uaredirect ("http://www.laozuo.org (change to your own WAP website)"); </script>
Both methods can be used. I can test it on Android and IPHONE.
The above two methods are used to redirect all content to the WAP mobile Website Based on the mobile browser type.