[Javascript] Keypress and a name jump
Mike Dougherty
mdougherty at pbp.com
Fri Jan 5 12:41:29 CST 2007
if you have the anchor an id you could also do this (i think/untested)
var obj = document.getElementById("jumptoId");
if (obj) { try{ obj.focus() } catch(e){ /* oops */ } }
ok, it's not pretty but it is fairly defensive
On Fri, 05 Jan 2007 18:03:59 +0100
Guillaume <javascript at webdesignofficina.com> wrote:
> Sorry this is a recall... I feel realy sorry if this one is disturbing your inbox...
>
> I can't believe no one has an answer:
>
> I'm using the function below to detect a keypress and I'd like also when this key is pressed to
>jump to a <a name="thereUgo"> in my document...
> Just as you would jump to a content <a name="thereUgo"> when you click on a <a
>href="#thereUgo>... Except that I try to do this with the keypress script below...
>
> Any ressource to point or solution to suggest ?
>
> Thanks.
>
> Guillaume.
>
> Here's the keypress script I use:
>
>
> function getKey(e){
>
> if (e == null) { // ie
>
> keycode = event.keyCode;
>
> } else { // mozilla
>
> keycode = e.which;
>
> }
>
> key = String.fromCharCode(keycode).toLowerCase();
>
>
> if(key == 't'){ myFunction(); }
>
>
> return false; }
>
> }
>
More information about the Javascript
mailing list