3

I have some Jquery scroller.

For desktop browsers I use this construction:

holder.bind('mousedown.rotate', function(e){
    //some actions  
    doc.bind('mousemove.dragrotate', function(e){
        //some actions          
    });
    doc.bind('mouseup.dragrotate', function(){
        //some actions  
        doc.unbind('.dragrotate');
    });
});

for mobile browsers it works in this way:

holder.bind('touchmove', function(jQueryEvent) {
//some actions
});

what is the best way to determine mobile borwsers? is there a way to use same function for all platforms?

thx

Kotanet
  • 573
  • 1
  • 8
  • 26

2 Answers2

3

You can use navigator.userAgent to check what browser the user is using... the following code would be a good starting point.

if (navigator.userAgent.match(/Android/i)
    || navigator.userAgent.match(/iPhone/i)
    || navigator.userAgent.match(/iPad/i)
    || navigator.userAgent.match(/iPod/i)
    || navigator.userAgent.match(/BlackBerry/i)
    || navigator.userAgent.match(/webOS/i)) {
    // Mobile browser specific code here
}

Detect Mobile Browsers has a JS file you can use if you want to get more specific.

sachleen
  • 30,730
  • 8
  • 78
  • 73
1
var is_touch_device = 'ontouchstart' in document.documentElement;

Detecting touch screen devices with Javascript

Community
  • 1
  • 1