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
sakfg
Posts: 224
Registered: ‎08-09-2011
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.

Please use plain text.
Regular Contributor
BertKoor
Posts: 81
Registered: ‎03-09-2012
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();
}

 

Please use plain text.
Trusted Contributor
sakfg
Posts: 224
Registered: ‎08-09-2011
My Carrier: BBprogrammer

Re: How to Know Wether Touch or NonTouch Using JS

Hi,

older devices it will not support this code
Please use plain text.
Regular Contributor
BertKoor
Posts: 81
Registered: ‎03-09-2012
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:

Please use plain text.
Contributor
kranthi4one
Posts: 31
Registered: ‎10-03-2011
My Carrier: developer

Re: How to Know Wether Touch or NonTouch Using JS

hi,

 

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

Please use plain text.