简体   繁体   English

如何定位具有jQuery移动功能的手机?

[英]How can I target jQuery mobile capable phones?

I've made a web-app using the jQuery Mobile framework for which I would like to provide a fall-back, for lower-spec phones. 我使用jQuery Mobile框架制作了一个网络应用程序,我想为其提供一个针对低规格手机的备用应用程序。

My question is... what is the best way to target JQM-capablephones? 我的问题是...定位支持JQM的电话的最佳方法是什么? I saw a similar question posted on the jquery forum. 我在jquery论坛上看到了类似的问题。 One of the answers suggested http://detectmobilebrowser.com/ which provides a long list of handsets. 建议的答案之一是http://detectmobilebrowser.com/ ,它提供了很多手机。

Is this the best way, or should I be testing for browser-capabilities rather than actually targeting handsets. 这是最好的方法,还是我应该测试浏览器功能,而不是实际针对手机。 If it is the latter what feaures are considered to be 'Grade-A' featues? 如果是后者,哪些特征被视为“ A级”特征?

Cheers 干杯

Progressive enhancement is what you should aim for, jQuery allows you to have a single codebase and have it work across the range of devices. 渐进式增强是您的目标,jQuery允许您使用单个代码库,并且可以在各种设备上使用。

Consider this: 考虑一下:

  • All links to other pages are regular html links, links will still work without AJAX support because they'd just send you to the location of the required page 指向其他页面的所有链接都是常规的html链接,在没有AJAX支持的情况下,链接仍然可以使用,因为它们只会将您发送到所需页面的位置

  • All major framework elements are built around lists, links, and a few divs. 所有主要框架元素都围绕列表,链接和一些div构建。 No HTML5 required for rendering content 无需HTML5即可呈现内容

  • At the bare minimum, all phones can display a good amount of styling, allowing you to display the content no matter how capable 最低限度,所有电话都可以显示大量样式,无论功能多么强大,您都可以显示内容

Do you have custom interfaces which wouldn't work at all without full support for jQuery mobile? 如果没有完全支持jQuery mobile,您是否有自定义界面根本无法使用?

I agree that graceful degradation is the best solution. 我同意,降级是最好的解决方案。 I would add that using the noscript tags is also a good way to provide graceful degradation by adding adding functionality via HTML for phones that have no support for JS. 我要补充一点,使用noscript标记也是一种不错的方法,可以通过为不支持JS的手机通过HTML添加添加功能来提供优美的降级效果。

I think it will be difficult to find a browser-capability (or even a set) that defines whether the phone will work with JQM. 我认为很难找到定义手机是否可以与JQM一起使用的浏览器功能(甚至是一组功能)。 In my own experience I have used WURFL, an open source device detection library, that provides capability information. 以我自己的经验,我曾使用WURFL(一个开放源代码设备检测库)来提供功能信息。 However I used it to target specific devices to include device specific CSS and remove all JS for other devices that I know do not support it (to remove the overhead of the JS being downloaded). 但是,我用它来定位特定设备以包括特定于设备的CSS,并删除了我不支持它的其他设备的所有JS(以消除正在下载的JS的开销)。

WURFL: http://wurfl.sourceforge.net/ WURFL: http ://wurfl.sourceforge.net/

JQM advertises that it provides graceful degradation: JQM宣传它提供了正常降级:

Graceful Degradation: jQuery Mobile uses the very best HTML 5 and CSS 3 features to provide the best possible experience in the most-capable browsers. 优雅降级:jQuery Mobile使用最好的HTML 5和CSS 3功能,以在功能最强大的浏览器中提供最佳体验。 However we don't consider this to be an all-or-nothing proposition: Less capable browsers will still receive the best possible experience that their platform can handle. 但是,我们不认为这是一个全有或全无的主张:性能不佳的浏览器仍将获得其平台可以处理的最佳体验。 They may not have all the gradients or fancy transitions of the best platforms but they'll still be highly usable. 它们可能没有最佳平台的所有渐变或花哨过渡,但它们仍将非常有用。 The most basic browsers will easily degrade back to simplified HTML and CSS. 最基本的浏览器将很容易降级为简化的HTML和CSS。

I have also tested multiple JQM pages in a single mobile page which work great (very speedy) in JQM but suffer from the same problem mentioned (all pages show up when javascript is turned off in the browser of a smart phone). 我还测试了单个移动页面中的多个JQM页面,这些页面在JQM中运行很好(非常快),但遇到了上述相同的问题(当在智能手机的浏览器中关闭javascript时,所有页面都会显示)。 To work around this issue, only use a single page per JQM page (you give up speed and uniform page transitioning though). 要变通解决此问题,每个JQM页仅使用一个页面(尽管您放弃了速度和统一的页面转换)。 In regards to the NOSCRIPT tag option, that tag is NOT universally recognized in all browsers. 关于NOSCRIPT标签选项, 并非所有浏览器都普遍认可该标签。 To work around that issue, you could try something like the following: 要变通解决此问题,您可以尝试执行以下操作:

<div id="no-js">
<!-- Place HTML without javascript here -->
</div>
<div id="js">
<script language="javascript">
// place javascript here which would be ignored by browsers not support javascript or with
// javascript turned off
document.getElementById("no-js").style.display = "none"; // be sure to hide the non javascript
// div
</script>
</div>

The above logic would work in either NOSCRIPT tag type browsers as well as those that do not recognize NOSCRIPT. 以上逻辑既可以在NOSCRIPT标记类型的浏览器中使用,也可以在不识别NOSCRIPT的浏览器中使用。

dlausch dlausch

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM