Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabled Left Click (for Psych Experiment), but focus changes in IE. How to prevent?

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>
like image 449
user605660 Avatar asked Nov 14 '22 02:11

user605660


1 Answers

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

like image 150
Nalum Avatar answered May 22 '23 22:05

Nalum