PHP How to detect jQuery mobile A grade browsers server side?

偶尔善良 提交于 2020-01-05 12:07:14

问题


I want to exclude the jQuery Mobile JS library from my header when a phone does not have "A grade" support as listed by jQuery Mobile (http://jquerymobile.com/gbs/). I find that on old Blackberry phones (that support JS) the jQM framework grinds these phones to a snails speed.

As an example these guys do a good job at serving up the jQuery Mobile library and associated styles depending on the mobile browser support: demo.livebookings.biz

How can I implement a similar server-side approach so that I can choose when to include JS files (e.g. jQM framework) and any CSS files as per the mobile browser support.

Thanks


回答1:


The jQM functionality is Client Side, More on this here:

  • http://jquerymobile.com/demos/1.0/docs/api/globalconfig.html

gradeA function that returns a boolean, default: a function returning the value of $.support.mediaquery
Any support conditions that must be met in order to proceed.

For Server Side you would need something like

  • http://code.google.com/p/mobileesp/
  • http://wurfl.sourceforge.net/

I've used Mobile ESP before and have had great results with it. It's also easy to extend/customize

  • http://code.google.com/p/mobileesp/source/browse/PHP/mdetect.php



回答2:


You have to do this by using the browsers user agent, but as there are so many its hard to do by your self (and keep it upto date), WURFL is a library that does all the hard work for you, works out the phone model and gives you the phones capabilities.

Using this you can find out whether the phone has certain features within the browsers and depending on what you call "A-grade" you can use JS libraries or not.

They have a pretty horrible website but the detailed library and PHP to read & cache it is all given to you.




回答3:


You can do this client-side by feature detection using the jQuery $.support() method:

<script src="jquery-1.6.4.js"></script>
<script>
//check to see if media queries are supported (this is how the jQuery Mobile framework detects "grade A" browsers), $.support.mediaquery returns true or false
if ($.support.mediaquery) {

    //if support is found then load the jQuery Mobile JS file
    $.getScript('jquery.mobile-1.0.js');
}
</script>

http://api.jquery.com/jquery.support

http://api.jquery.com/jquery.getscript



来源:https://stackoverflow.com/questions/8174083/php-how-to-detect-jquery-mobile-a-grade-browsers-server-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!