Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Trusted Contributor
Posts: 224
Registered: ‎08-09-2011
My Device: 9550
My Carrier: BBprogrammer

How to Know Wether Touch or NonTouch Using JS

Hi all,

 

     I want to know the small quostion,Is it possible to findout wether the BBdevice is Touch or Non-Touch  Using JavaScript.

Regular Contributor
Posts: 81
Registered: ‎03-09-2012
My Device: PlayBook & Bold 9780
My Carrier: n/a

Re: How to Know Wether Touch or NonTouch Using JS

[ Edited ]

I put this at the top of the JavaScript

 

var hasTouch = "ontouchstart" in document.documentElement;

 So furtheron I can do things like

 

var x = (hasTouch) ? 1 : 2;

if (hasTouch) {
doTouch();
} else {
doNonTouch();
}

 

Trusted Contributor
Posts: 224
Registered: ‎08-09-2011
My Device: 9550
My Carrier: BBprogrammer

Re: How to Know Wether Touch or NonTouch Using JS

Hi,

older devices it will not support this code
Regular Contributor
Posts: 81
Registered: ‎03-09-2012
My Device: PlayBook & Bold 9780
My Carrier: n/a

Re: How to Know Wether Touch or NonTouch Using JS

[ Edited ]

Well, the Document JavaScript object had a major change in OS 4.6. So any device prior to that probably won't accept the code, but those devices also don't support touch. And they miss a lot of other features, so it's going to be problematic supporting them. Maybe it works to put a try-catch around that code and set the variable to false if it fails.

 

What OS versions have you tested that don't support that code? Maybe just draw the line there...

The first touch devices were the Storm 9500/9530 running on OS v4.7, so maybe below OS v5.0 is a good point to stop supporting.

 

Here are some lists with device capabilities:

Highlighted
Contributor
Posts: 32
Registered: ‎10-03-2011
My Device: 9900
My Carrier: developer

Re: How to Know Wether Touch or NonTouch Using JS

hi,

 

    var isTouch = blackberry.system.hasCapability('input.touch');