With the popularization of mobile devices, the enterprise's network propaganda can not be limited to the PC side, but also need to contribute to the mobile end of the achievements. For the company's website, the previous is done by the PC side, of course, mobile phones and other mobile end can also access, but the user experience is certainly not as good as the full fit of the phone to the convenience. We have done to their own website WAP Mobile website, if there are users through the mobile phone to visit our corporate top-level domain Web site, it will be judged to jump to a dedicated WAP site.
Here old left collation to the current oneself in the use of 2 of JS script, because there have been friends with me, so here to share it out.
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 (replace to own WAP web site)";
}} catch (Err)
{
The second type, 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.
<script src= "Mobile.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" > Uaredirect ("http://www.laozuo.org (replace to own WAP website)");</script>
After my test two JS script can be judged mobile browser type to jump WAP mobile phone site, the need for friends to take the past use directly.