Martin
Martin

Reputation: 10563

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

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

Upvotes: 1

Views: 1542

Answers (3)

Phill Pafford
Phill Pafford

Reputation: 85298

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

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

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

Upvotes: 1

Jasper
Jasper

Reputation: 75993

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

Upvotes: 1

472084
472084

Reputation: 17885

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.

Upvotes: 1

Related Questions