[thelist] [Javascript] click() not working with Safari
J.J.SOLARI
jjsolari at pobox.com
Sat Jun 18 08:38:56 CDT 2005
Hello all,
Still polishing up a Web application, that is making it work with
target browsers (IE5+, Gecko-based browsers, Opera, and Safari), I
am having a hard time with the later.
Basically, there are accesskeys assigned to some form elements; a
Javascript script performs some action on them (check or uncheck
radio buttons or checkboxes, or submit-like buttons) when pressing a
particular key. The script simulates the behaviour of a accesskey
Html attribute, but without a modifier key (alt or ctrl).
The code is roughly the following:
// on load
function init()
{
// set a keyup event on document
document.onkeyup = accessKeyup;
...
document.getElementById("some_button").onclick = checkClick;
document.getElementById("another_button").onclick = checkClick2;
...
}
// check if conditions are met as to avoid unnecessary Http requests
function checkClick( ) // or checkClick2( )
{
// do some checking
if( ... ) return false;
else return true;
}
// process key event
function accessKeyup( e )
{
var btn = null;
...
e = ( e ) ? e : window.event;
switch( e.keyCode )
{
// key: l
case 76: btn = "some_button";
break;
case 77: btn = "another_button";
...
default:
break;
}
if( btn )
{
var check_action = null"
switch( btn )
{
case "some_button": check_action = checkClick();
break;
case "another_button": check_action = checkClick2();
...
default: check_action = true;
break;
}
if( check_action )
{
document.getElementById( btn ).click();
}
}
...
}
This would work with IE5+, Gecko-based browsers, Opera 8.x, but
Safari2.0.
If this is a Safari bug, any workaround is welcome.
TIA,
JJS.
More information about the thelist
mailing list