I've enabled the "Emulate Touch Events" option in Chrome's Developer Tools. I set up a simple test program that alerts when I touch a <div>
. The program works fine on my Galaxy Nexus, but when I click on the <div>
in Chrome, even with the "Emulate Touch Events" option enabled, nothing happens. Any suggestions? Am I using this tool correctly?
Here's my code - nothing too fancy.
<!DOCTYPE html>
<html lang="en">
<head>
<style type="text/css">
#main_div
{
position: absolute;
width: 50px;
height: 20px;
background-color: red;
top: 50%;
left: 20px;
}
</style>
<script type="text/javascript">
function init()
{
main_div = document.getElementById("main_div");
main_div.ontouchstart = function()
{
alert("here");
}
}
</script>
</head>
<body onload="init()">
<div>
<p id="x">hello</p>
<p id="y"></p>
</div>
<div id="main_div">
hello
</div>
</body>
</html>
What stumped me was that in addition to having the "Emulate touch events" checkbox checked, you also have to have the master "Enable" checkbox checked to enable overrides. Once both were checked, it worked fine.
Touch events work in Chrome version 21 (not sure about previous versions) BUT you have to keep the Developer Tools window open in order for the touch events to occur. If you close the window you will go back to normal mouse events.
As of Chrome 69, there's no Overrides pane in the settings, nor an Emulator drawer in the console. Instead, you can click the ...
icon in the device view and then select "Add device type".
While in Responsive mode, this will show you a little dropdown with the options "Mobile", "Mobile (no touch)", "Desktop", and "Desktop (no touch)". If you don't see it, expand the width of the device view pane. The default for Responsive mode is Mobile (which means touch events).
Note that when you select other pre-set devices, the device type will be set to Mobile and can't be changed. You can also select which device type you'd like to emulate when creating a custom device in Settings.
One important point that I've noticed - Checking "Emulate touch events" does not disable mouse events, it only adds a touch as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With