如何检查天气的设备是iPad和平板电脑在phonegap [英] How to check weather the device is iPad and tablet in phonegap

查看:143
本文介绍了如何检查天气的设备是iPad和平板电脑在phonegap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查设备在phonegap?。实际上我需要我的应用程序只运行平板电脑或在Iphone。我需要在其他手机上阻止我的应用程序只运行Android平板电脑或在iphone ipad.is它可以检查



感谢

解决方案

简介



有几种可用的解决方案。有些是由javascript提供的,有些是免费的,有些是付费服务。另外一些是服务器端,一些是客户端,但是从这个邮件,我认为你需要客户端解决方案。



客户端检测:



Modernizer -


好酷的新web技术的好处是很有趣,直到你
已经支持浏览器落后。 Modernizr使
变得容易,您可以编写条件JavaScript和CSS来处理每种情况,
是否支持某个功能。


好:
$ b

只有客户端,服务器端组件不存在



快速但对于一个具有12kb的javascript框架仍然很大。


$ b

差:



Modernizr本身是了解用户浏览器功能的好方法。但是,您只能在浏览器上访问其API,这意味着您无法从知道您的服务器逻辑中的浏览器功能中获益。





示例:

 <!DOCTYPE html& 
< html>
< head>
< meta charset =utf-8>
< title> Modernizr示例< / title>
< script src =modernizr.min.js>< / script>
< / head>
< body>
< script>
if(Modernizr.canvas){
// supported
} else {
//没有本地画布支持(

< script>
< / body>
< / html>

strong> 基于JavaScript的浏览器嗅探


这可能是(学术上)最糟糕的可能的方式
检测移动,但它有它的美德。


好:



简单



strong> Bad:



它只会告诉设备类型,但不会提供设备版本,例如它会告诉你我们使用iPad,如果是版本1,2或3。



示例:

 < script type =text / javascript> 
var agent = navigator.userAgent;
var isWebkit =(agent.indexOf(AppleWebKit)& 0);
var isIPad =(agent.indexOf(iPad)> 0);
var isIOS =(agent.indexOf(iPhone)> 0 || agent.indexOf(iPod)> 0);
var isAndroid =(agent.indexOf(Android)> 0);
var isNewBlackBerry =(agent.indexOf(AppleWebKit)> 0&&&&& amp;&&&&& amp;> 0
var isWebOS =(agent.indexOf(webOS)> 0);
var isWindowsMo​​bile =(agent.indexOf(IEMobile)> 0);
var isSmallScreen =(screen.width< 767 ||(isAndroid&&& screen.width< 1000));
var isUnknownMobile =(isWebkit& isSmallScreen);
var isMobile =(isIOS || isAndroid || isNewBlackBerry || isWebOS || isWindowsMo​​bile || isUnknownMobile);
var isTablet =(isIPad ||(isMobile&!amp;!isSmallScreen));

if(isMobile& isSmallScreen&&& document.cookie.indexOf(mobileFullSiteClicked =)< 0)mobileRedirect
< / script>



更多信息



/回答这个主题。查找 此处 a>


How to check device in phonegap?.Actually i need that my application is only run only tablet or in Iphone .I need to block my application on other phones only run Android tablet or in iphone Ipad.is it possible to check in phonegap..?

Thanks

解决方案

Intro

There are several available solutions. Some are provided by javascript, some are free and some are paid services. Plus some are server side and some are client side but from this mail I think you need client side solutions.

Client side detection:

Modernizer -

aking advantage of cool new web technologies is great fun, until you have to support browsers that lag behind. Modernizr makes it easy for you to write conditional JavaScript and CSS to handle each situation, whether a browser supports a feature or not. It’s perfect for doing progressive enhancement easily.

Good :

Only client side, server side component don't exist

Fast but still large for a javascript framework with its 12kb. Because of its modularity it can become smaller, depending on your needs.

Bad :

Can do only so much, less info then server side detection.

Modernizr itself is a great way to find out about your user’s browser capabilities. However, you can only access its API on the browser itself, which means you can’t easily benefit from knowing about browser capabilities in your server logic.

Example :

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Modernizr Example</title>
      <script src="modernizr.min.js"></script>
    </head>
    <body>
      <script>
        if (Modernizr.canvas) {
          // supported
        } else {
          // no native canvas support available :(
        }  
      </script>
    </body>
    </html>

JavaScript based browser sniffing

It is arguable that this may be (academically) the worst possible way to detect mobile but it does have its virtues.

Good :

Simple

Bad :

It will only tell device type, but it will not provide device version. For example it will tell you that iPad us used but not if it is version 1,2 or 3.

Example :

<script type="text/javascript">     
    var agent = navigator.userAgent;      
    var isWebkit = (agent.indexOf("AppleWebKit") > 0);      
    var isIPad = (agent.indexOf("iPad") > 0);      
    var isIOS = (agent.indexOf("iPhone") > 0 || agent.indexOf("iPod") > 0);     
    var isAndroid = (agent.indexOf("Android")  > 0);     
    var isNewBlackBerry = (agent.indexOf("AppleWebKit") > 0 && agent.indexOf("BlackBerry") > 0);     
    var isWebOS = (agent.indexOf("webOS") > 0);      
    var isWindowsMobile = (agent.indexOf("IEMobile") > 0);     
    var isSmallScreen = (screen.width < 767 || (isAndroid && screen.width < 1000));     
    var isUnknownMobile = (isWebkit && isSmallScreen);     
    var isMobile = (isIOS || isAndroid || isNewBlackBerry || isWebOS || isWindowsMobile || isUnknownMobile);     
    var isTablet = (isIPad || (isMobile && !isSmallScreen));     

    if ( isMobile && isSmallScreen && document.cookie.indexOf( "mobileFullSiteClicked=") < 0 ) mobileRedirect(); 
</script>

More info

I have another article/answer about this topic. Find it HERE.

这篇关于如何检查天气的设备是iPad和平板电脑在phonegap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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