在ASP.NET从移动浏览器检测请求 [英] Detecting Requests from Mobile Browsers in ASP.NET

查看:104
本文介绍了在ASP.NET从移动浏览器检测请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的网站,我想创建它的移动版本,更适合。例如,主站点使用下拉菜单,我们都知道那是相当的失败,在移动设备上。

I have an existing web site and I would like to create a mobile version of it that is more suitable. For instance, the main site uses drop-down menus and we all know those are quite the fail on mobile devices.

我想重定向到我的移动版本(这将是当前网站的子域),如果我检测到来自移动浏览器的请求。因此,当他们谷歌的东西,来到我的网站,他们将自动看到移动版本(就像维基百科)。

I would like to redirect to my mobile version (it will be a subdomain of the current site) if I detect a request from a mobile browser. So when they Google something and come to my site, they will automatically see the mobile version (just like Wikipedia).

确实ASP.NET提供了这样一个简单的方法?如果不是这样,我该怎么办呢?

Does ASP.NET provide an easy way of doing this? If not, how can I do it?

推荐答案

请简单...

继承人的JS在同一...

Heres the JS for the same...

希望它可以帮助别人。

var useragent = navigator.userAgent;

var isMobile = !!useragent.match(/iPhone|Android|Blackberry|Sony|Nokia|Motorola|Samsung/i),
    isWebBrowser = !!useragent.match(/Mozilla/i);

// Redirect the call accordingly.

  if(isWebBrowser && !isMobile)
            //call to web portal
            alert(" You seem to me... calling from Web Browser")
    else if(isMobile)
        //call to mobile apps
            alert(" Call seems to be from Mobile device...")
    else
    {
        // jus kiddin...
        alert(" Unable to detect the device..... Please report to admin...")
    }

这篇关于在ASP.NET从移动浏览器检测请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆