views:

114

answers:

2

Does anyone know if it's possible to determine, using JavaScript, whether the user's browser allows checkboxes and radio buttons to be focused? In other words, whether you can tab to select them.

I can't just use browser detection to do this, because in at least one case (Safari), the user can turn the ability on and off.

Also in Safari, the focus() function is defined even when this ability is turned off, and it doesn't throw an error. So checking that function won't work.

A: 

JavaScript cannot read the browser's settings. Doing so would be a security violation.

That being said, there is no way to test for something not happening if it requires the user's interaction without giving them explicit directions so to perform the testable action. So there is no passive way to test for the user having disabled tabbing.

It's rather like changing screen resolution in Windows. The user changes resolution and because VGA is passive there's no way for the OS to tell whether that change was successful unless the user performs an action. You need to ask them, set a timeout and assume it doesn't work if you get a negative result. You can't tell the difference between a negative result an no user interaction.

Diodeus
+1  A: 

One approach is to try to set the focus and then detect if it was successful. Do this by assigning an onfocus event that set a variable to true, try to focus it and then check if the variable is true.

some