2013-04-15 182 views
1

Whic是接下来要做的最好办法:我有正规的网站手机网站检测

,让说:www.regular.com(例如) 和移动网站:mobile.regular.com

如果有人通过手机获得在正规网站(iPhone,Android和等..),它进入到页面谁给2种选择:

1)获取定期现场

2)获得在手机网站

到目前为止,我做了下一个:

<a href="http://mobile.regular.com">To Mobile site</a> 

<a id="fullsite" href="http://regular.com">To regular site</a> 

    <script type="text/javascript"> 
    document.getElementById('fullsite').addEventListener('click',gotoFullSite,true); 

    function gotoFullSite(e) { 
    e.preventDefault(); 
    setCookie("viewFullSite", true, 1); 
    location.href = this.getAttribute('http://regular.com'); 
    } 
    </script> 

如果用户是从移动还是不是我需要把正规网站,以自动识别?这样做的方式是,如果有人想反正显示常规站点,即使通过移动设备?

如果其重要:

的移动网站是在WordPress的

定期到现场是在ASP.NET C#

+0

感谢所有Finnaly我找到了答案在这里:[S解决方案](http://www.malphursinteractive.com/view-full-site-mobile-redirect-script/) – Oshrib

回答

0

在PHP中的可用于检测设备/通道库。例如Mobile Detect就是一个这样的库文件。试试看。

0

使用IsMobileDevice标志。

尝试:

Request.Browser.IsMobileDevice 

重定向:

Response.Status="302 Moved Temporarily" 
Response.AddHeader "Location","http://m.yoursite.com" 

希望它有帮助。

+0

嗨,谢谢。可以说我在普通网站的default.aspx上完成了它......在用户从移动设备上选择“去常规站点”之后会发生什么?它会将他带回移动网站,不是吗? – Oshrib

0

您应该使用WURFL在服务器端执行此操作。它有可用于本地.NET集成的版本,以及您可以在链接中看到的版本。

所有其他方法都(更)不可靠和/或不标准化,例如IsMobileDevice标志(也是笔记本电脑,移动设备或没有?和触摸屏?混合笔记本电脑/平板电脑?)

+0

虽然它不是免费的 – Lanorkin

0
function IsMobile() { 
var navi = navigator.userAgent.toLowerCase(); 
if(navi.match(/android/i) 
    || navi.match(/webos/i) 
    || navi.match(/iphone/i) 
    || navi.match(/ipad/i) 
    || navi.match(/ipod/i) 
    || navi.match(/blackberry/i) 
    || navi.match(/windows phone/i) 
) 
{ 
    window.location.href = "http://mobile.regular.com"; 
}  
} 

$(document).ready(function(){ 
    IsMobile(); 
    //do code for regular site 
}); 
1

在Javascript中:

if(navigator.userAgent.match(/Android|webOS|iPhone|iPod|BlackBerry|iPad/i)){ 
alert("I am mobile browser"); 
}else { 
alert("I am desktop browser"); 
} 

在C#:

if (Request.Headers["User-Agent"] != null && (Request.Browser["IsMobileDevice"] == "true" || Request.Browser["BlackBerry"] == "true"||request.UserAgent.ToLower().Contains("iphone")) 
{ 
Response.Redirect("http://Yourwebsite.com"); 
}