手机打开网站如何自动跳转到移动站

 areay   2015-11-21 23:45   381 人阅读  0 条评论

如何让网民在使用手机等移动设备的时候打开网站 自动跳转到移动站点,下面是几段跳转代码。操作简单。

第一段代码:

<script language="JavaScript">// <![CDATA[
function mobile_device_detect(url)
{
var thisOS=navigator.platform;
var os=new Array("iPhone","iPod","iPad","android","Nokia","SymbianOS","Symbian","Windows Phone","Phone","Linux armv71","MAUI","UNTRUSTED/1.0","Windows CE","BlackBerry","IEMobile");
for(var i=0;i<os.length;i++)
{
if(thisOS.match(os[i]))
{
window.location=url;
}
}
//因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认
if(navigator.platform.indexOf('iPad') != -1)
{
window.location=url;
}
//做这一部分是因为Android手机的内核也是Linux
//但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appVersion信息做判断
var check = navigator.appVersion;
if( check.match(/linux/i) )
{
//X11是UC浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件
if(check.match(/mobile/i) || check.match(/X11/i))
{
window.location=url;
}
}
//类in_array函数
Array.prototype.in_array = function(e)
{
for(i=0;i
<this.length;i++)   {   if(this[i] == e)   return true;   }   return false;   }   }   mobile_device_detect("http://***.***.com");
// ]]></script>

注:mobile_device_detect("http://***.***.com");//里面的地址填的就是您的移动端的网站地址。

还有其他代码也同样可以实现,对程序代码略懂的朋友可以多尝试方法来解决。下面在给大家介绍一段代码来实现移动站点的跳转。

<script type="text/javascript">
if(/AppleWebKit.*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|

MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){
if(window.location.href.indexOf("?via=")<0){
try{
if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){
window.location.href="http://移动网址/?via=index";
}else if(/iPad/i.test(navigator.userAgent)){
}else{
window.location.href="http://移动网址/?j=simple&via=index"
}
}catch(e){}
}
}
</script>


本文地址:http://wangshuming.cn/article/44.html
免责声明:本文为转载文章,来源于网络,文章版权归原作者所有。若因本站的引用侵犯了您的版权权利,麻烦发邮件49212578@qq.com联系我们及时删除,谢谢。

 发表评论


表情

还没有留言,还不快点抢沙发?