I am conducting some Psych experiment on web design, and I want to disable both mouse clicks. (Please ignore usability issues. I know about them. I intentionally do this for the purpose of my psych experiment.)
So far I succeeded disabling both clicks in Firefox, Chrome, and Safari. In IE, however, when I left click, focus still changes to the place I clicked. I want to stop this behavior (i.e. focus remains the place before I click). It doesn't matter whether the system produces alert or not, because I'm going to use alert anyway.
I appreciate if some of you can help me. Please note that I CAN'T use JQuery. My experiment tool cannot handle JQuery well.
<html>
<head>
</head>
<body>
<div>
<select>
<option> aa </option>
</select>
</div>
<div>
<select>
<option> aa </option>
</select>
</div>
<script type="text/javascript">
function mousehandler(){
alert("For the purpose of psych experiment, you can't use mouse.");
return false;
}
document.oncontextmenu = mousehandler;
document.onmousedown = mousehandler;
</script>
</body>
</html>
Not sure why IE8 is doing this but if you are setting the second select to have focus when the page loads, then in your mousehandler()
function if you add setTimeout(function(){document.getElementsByTagName("select")[1].focus();},1);
before the return false you can give the second select it's focus back. It then appears that it never lost focus to the first select.
The reason for setTimeout()
is because without it the first select will gain focus.
function mousehandler(){
alert("For the purpose of psych experiment, you can't use mouse.");
setTimeout(function(){document.getElementsByTagName("select")[1].focus();},1);
return false;
}
EDIT: jsFiddle example
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