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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -