javascript - Detect if input was touched (tablet) or clicked (mouse) -


we developing web-app, launches on desktop , on tablets (ipad, android or surface). building our own keyboard number inputs. when set focus on input field mousclick, costum keyboard opens correct. when set focus input touched click (tablet), default keyboard opens also. our idea is, detect, if there mouse-click or touched click. if it's touched click, can set readonly="true" property input, default keyboard on tabled wouldn't slide in.

is there way detect or check "type" of click (touched or mouse).

you can define event both actions touchend , click detect 1 triggered using type of event :

$('#element-id').on('click touchend',function(e){    if(e.type=='click')        console.log('mouse click');    else        console.log('touch');  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <button id="element-id">click here</button>

hope helps.


Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -