【问题标题】:Mobile site detecting移动站点检测
【发布时间】:2023-03-21 18:04:01
【问题描述】:

下一步最好的方法是:

我有常规网站,比如说: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#

【问题讨论】:

  • 感谢所有 Finnaly,我在这里找到了答案:Solution

标签: c# php javascript asp.net mobile


【解决方案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");
}

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

        【解决方案4】:

        使用IsMobileDevice 标志。

        尝试:

        Request.Browser.IsMobileDevice
        

        重定向:

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

        希望对您有所帮助。

        【讨论】:

        • 嗨,谢谢。假设我是在常规站点的 default.aspx 处完成的...在用户从移动设备中选择“转到常规站点”后会发生什么?它会让他回到移动网站,不是吗?
        【解决方案5】:
        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
        });
        

        【讨论】:

          猜你喜欢
          • 2012-01-20
          • 2015-01-13
          • 1970-01-01
          • 1970-01-01
          • 2012-03-24
          • 2013-12-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多