onKeyPress for a link

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • juglesh

    onKeyPress for a link

    hello, I just want to be able to use a keypress to do the same as clicking a
    link. such as [right arrow] will 'click' a certain link, while [left arrow]
    will 'click' a different link.

    thanks for your time,
    juglesh B>{)}


  • Nik Coughin

    #2
    Re: onKeyPress for a link

    juglesh wrote:[color=blue]
    > hello, I just want to be able to use a keypress to do the same as
    > clicking a link. such as [right arrow] will 'click' a certain link,
    > while [left arrow] will 'click' a different link.
    >
    > thanks for your time,
    > juglesh B>{)}[/color]

    <script type="text/javascript">
    function keyHandler( e )
    {

    if( !e )
    {
    e = window.event;
    }

    arrowUp = 38;
    arrowDown = 40;
    arrowLeft = 37;
    arrowRight = 39;

    switch( e.keyCode )
    {
    case arrowUp:
    //Do something
    break;
    case arrowDown:
    //Do something
    break;
    case arrowLeft:
    //Do something
    break;
    case arrowRight:
    //Do something
    break;
    }
    }

    document.onkeyd own = keyHandler;
    </script>


    Comment

    • juglesh

      #3
      Re: onKeyPress for a link


      "Nik Coughin" <nrkn!no-spam!@woosh.co. nz> wrote in message
      news:bfcOd.1623 3$mo2.1286145@n ews.xtra.co.nz. ..[color=blue]
      > juglesh wrote:[color=green]
      >> hello, I just want to be able to use a keypress to do the same as
      >> clicking a link. such as [right arrow] will 'click' a certain link,
      >> while [left arrow] will 'click' a different link.
      >>
      >> thanks for your time,
      >> juglesh B>{)}[/color]
      >
      > <script type="text/javascript">
      > function keyHandler( e )
      > {
      >
      > if( !e )
      > {
      > e = window.event;
      > }
      >
      > arrowUp = 38;
      > arrowDown = 40;
      > arrowLeft = 37;
      > arrowRight = 39;
      >
      > switch( e.keyCode )
      > {
      > case arrowUp:
      > //Do something
      > break;
      > case arrowDown:
      > //Do something
      > break;
      > case arrowLeft:
      > //Do something
      > break;
      > case arrowRight:
      > //Do something
      > break;
      > }
      > }
      >
      > document.onkeyd own = keyHandler;
      > </script>[/color]

      ok, thanks, that works. the reason I was thinking it should click a certain
      link on the page is cuz php is writing out the link for me, and will be
      different each page. is there any way for javascript to 'click ' a link?

      I'm just having php write out this javascript you gave me, so my problem is
      solved without the < javascript 'click ' a link> question.

      j


      Comment

      • Nik Coughin

        #4
        Re: onKeyPress for a link

        juglesh wrote:[color=blue]
        > "Nik Coughin" <nrkn!no-spam!@woosh.co. nz> wrote in message
        > news:bfcOd.1623 3$mo2.1286145@n ews.xtra.co.nz. ..[color=green]
        >> juglesh wrote:[color=darkred]
        >>> hello, I just want to be able to use a keypress to do the same as
        >>> clicking a link. such as [right arrow] will 'click' a certain link,
        >>> while [left arrow] will 'click' a different link.
        >>>
        >>> thanks for your time,
        >>> juglesh B>{)}[/color]
        >>
        >> <script type="text/javascript">
        >> function keyHandler( e )
        >> {
        >>
        >> if( !e )
        >> {
        >> e = window.event;
        >> }
        >>
        >> arrowUp = 38;
        >> arrowDown = 40;
        >> arrowLeft = 37;
        >> arrowRight = 39;
        >>
        >> switch( e.keyCode )
        >> {
        >> case arrowUp:
        >> //Do something
        >> break;
        >> case arrowDown:
        >> //Do something
        >> break;
        >> case arrowLeft:
        >> //Do something
        >> break;
        >> case arrowRight:
        >> //Do something
        >> break;
        >> }
        >> }
        >>
        >> document.onkeyd own = keyHandler;
        >> </script>[/color]
        >
        > ok, thanks, that works. the reason I was thinking it should click a
        > certain link on the page is cuz php is writing out the link for me,
        > and will be different each page. is there any way for javascript to
        > 'click ' a link?
        > I'm just having php write out this javascript you gave me, so my
        > problem is solved without the < javascript 'click ' a link> question.
        >
        > j[/color]

        Easiest way to do it is probably change the document.locati on:

        case arrowLeft:
        document.locati on.href = "page1.html ";
        break;
        case arrowRight:
        document.locati on.href = "page3.html ";
        break;


        Comment

        • RobB

          #5
          Re: onKeyPress for a link

          Nik Coughin wrote:[color=blue]
          > juglesh wrote:[color=green]
          > > "Nik Coughin" <nrkn!no-spam!@woosh.co. nz> wrote in message
          > > news:bfcOd.1623 3$mo2.1286145@n ews.xtra.co.nz. ..[color=darkred]
          > >> juglesh wrote:
          > >>> hello, I just want to be able to use a keypress to do the same as
          > >>> clicking a link. such as [right arrow] will 'click' a certain[/color][/color][/color]
          link,[color=blue][color=green][color=darkred]
          > >>> while [left arrow] will 'click' a different link.
          > >>>
          > >>> thanks for your time,
          > >>> juglesh B>{)}
          > >>
          > >> <script type="text/javascript">
          > >> function keyHandler( e )
          > >> {
          > >>
          > >> if( !e )
          > >> {
          > >> e = window.event;
          > >> }
          > >>
          > >> arrowUp = 38;
          > >> arrowDown = 40;
          > >> arrowLeft = 37;
          > >> arrowRight = 39;
          > >>
          > >> switch( e.keyCode )
          > >> {
          > >> case arrowUp:
          > >> //Do something
          > >> break;
          > >> case arrowDown:
          > >> //Do something
          > >> break;
          > >> case arrowLeft:
          > >> //Do something
          > >> break;
          > >> case arrowRight:
          > >> //Do something
          > >> break;
          > >> }
          > >> }
          > >>
          > >> document.onkeyd own = keyHandler;
          > >> </script>[/color]
          > >
          > > ok, thanks, that works. the reason I was thinking it should click[/color][/color]
          a[color=blue][color=green]
          > > certain link on the page is cuz php is writing out the link for me,
          > > and will be different each page. is there any way for javascript[/color][/color]
          to[color=blue][color=green]
          > > 'click ' a link?
          > > I'm just having php write out this javascript you gave me, so my
          > > problem is solved without the < javascript 'click ' a link>[/color][/color]
          question.[color=blue][color=green]
          > >
          > > j[/color]
          >
          > Easiest way to do it is probably change the document.locati on...[/color]

          (snip)

          Except that it's *window*.locati on. document.locati on is deprecated,
          although many user agents seem to have mapped it to window.location (in
          other words, it works) - but it's still incorrect. btw,
          document.locati on is now document.URL.

          The MDN Web Docs site provides information about Open Web technologies including HTML, CSS, and APIs for both Web sites and progressive web apps.


          Comment

          • juglesh

            #6
            Re: onKeyPress for a link


            "Nik Coughin" <nrkn!no-spam!@woosh.co. nz> wrote in message
            news:E6fOd.1630 2$mo2.1288731@n ews.xtra.co.nz. ..[color=blue]
            > juglesh wrote:[color=green]
            >> "Nik Coughin" <nrkn!no-spam!@woosh.co. nz> wrote in message
            >> news:bfcOd.1623 3$mo2.1286145@n ews.xtra.co.nz. ..[color=darkred]
            >>> juglesh wrote:
            >>>> hello, I just want to be able to use a keypress to do the same as
            >>>> clicking a link. such as [right arrow] will 'click' a certain link,
            >>>> while [left arrow] will 'click' a different link.
            >>>>
            >>>> thanks for your time,
            >>>> juglesh B>{)}
            >>>
            >>> <script type="text/javascript">
            >>> function keyHandler( e )
            >>> {
            >>>
            >>> if( !e )
            >>> {
            >>> e = window.event;
            >>> }
            >>>
            >>> arrowUp = 38;
            >>> arrowDown = 40;
            >>> arrowLeft = 37;
            >>> arrowRight = 39;
            >>>
            >>> switch( e.keyCode )
            >>> {
            >>> case arrowUp:
            >>> //Do something
            >>> break;
            >>> case arrowDown:
            >>> //Do something
            >>> break;
            >>> case arrowLeft:
            >>> //Do something
            >>> break;
            >>> case arrowRight:
            >>> //Do something
            >>> break;
            >>> }
            >>> }
            >>>
            >>> document.onkeyd own = keyHandler;
            >>> </script>[/color]
            >>
            >> ok, thanks, that works. the reason I was thinking it should click a
            >> certain link on the page is cuz php is writing out the link for me,
            >> and will be different each page. is there any way for javascript to
            >> 'click ' a link?
            >> I'm just having php write out this javascript you gave me, so my
            >> problem is solved without the < javascript 'click ' a link> question.
            >>
            >> j[/color]
            >
            > Easiest way to do it is probably change the document.locati on:
            >
            > case arrowLeft:
            > document.locati on.href = "page1.html ";
            > break;
            > case arrowRight:
            > document.locati on.href = "page3.html ";
            > break;[/color]

            yeah, that's what I did. uh, except I forgot the .href, seems to be
            working, though...I used window.location actually. pros and cons?



            Comment

            • RobB

              #7
              Re: onKeyPress for a link

              juglesh wrote:[color=blue]
              > "Nik Coughin" <nrkn!no-spam!@woosh.co. nz> wrote in message
              > news:E6fOd.1630 2$mo2.1288731@n ews.xtra.co.nz. ..[color=green]
              > > juglesh wrote:[color=darkred]
              > >> "Nik Coughin" <nrkn!no-spam!@woosh.co. nz> wrote in message
              > >> news:bfcOd.1623 3$mo2.1286145@n ews.xtra.co.nz. ..
              > >>> juglesh wrote:
              > >>>> hello, I just want to be able to use a keypress to do the same[/color][/color][/color]
              as[color=blue][color=green][color=darkred]
              > >>>> clicking a link. such as [right arrow] will 'click' a certain[/color][/color][/color]
              link,[color=blue][color=green][color=darkred]
              > >>>> while [left arrow] will 'click' a different link.
              > >>>>
              > >>>> thanks for your time,
              > >>>> juglesh B>{)}
              > >>>
              > >>> <script type="text/javascript">
              > >>> function keyHandler( e )
              > >>> {
              > >>>
              > >>> if( !e )
              > >>> {
              > >>> e = window.event;
              > >>> }
              > >>>
              > >>> arrowUp = 38;
              > >>> arrowDown = 40;
              > >>> arrowLeft = 37;
              > >>> arrowRight = 39;
              > >>>
              > >>> switch( e.keyCode )
              > >>> {
              > >>> case arrowUp:
              > >>> //Do something
              > >>> break;
              > >>> case arrowDown:
              > >>> //Do something
              > >>> break;
              > >>> case arrowLeft:
              > >>> //Do something
              > >>> break;
              > >>> case arrowRight:
              > >>> //Do something
              > >>> break;
              > >>> }
              > >>> }
              > >>>
              > >>> document.onkeyd own = keyHandler;
              > >>> </script>
              > >>
              > >> ok, thanks, that works. the reason I was thinking it should click[/color][/color][/color]
              a[color=blue][color=green][color=darkred]
              > >> certain link on the page is cuz php is writing out the link for[/color][/color][/color]
              me,[color=blue][color=green][color=darkred]
              > >> and will be different each page. is there any way for javascript[/color][/color][/color]
              to[color=blue][color=green][color=darkred]
              > >> 'click ' a link?
              > >> I'm just having php write out this javascript you gave me, so my
              > >> problem is solved without the < javascript 'click ' a link>[/color][/color][/color]
              question.[color=blue][color=green][color=darkred]
              > >>
              > >> j[/color]
              > >
              > > Easiest way to do it is probably change the document.locati on:
              > >
              > > case arrowLeft:
              > > document.locati on.href = "page1.html ";
              > > break;
              > > case arrowRight:
              > > document.locati on.href = "page3.html ";
              > > break;[/color]
              >
              > yeah, that's what I did. uh, except I forgot the .href, seems to be
              > working, though...I used window.location actually. pros and cons?[/color]

              According to David Flanagan (JavaScript: The Definitive Guide,
              O'Reilly):

              In addition to its properties, the Location object can be used as if it
              were itself a primitive string value. If you read the value of a
              Location object, you get the same string as you would if you read the
              href property of the object (this is because the Location object has a
              suitable toString() method). What is far more interesting, though, is
              that you can assign a new URL string to the location property of a
              window. Assigning a URL to the Location object like this has a very
              important side effect: it causes the browser to load and display the
              contents of the URL you assign (this side effect occurs because the
              Location has a suitable assign() method).

              While you might expect there to be a method you can call to make the
              browser display a new web page, assigning a URL to the location
              property of a window is the supported technique to accomplish this.

              Comment

              Working...