views:

416

answers:

1

I have a simple ASP.NET page with a paging support. Basically just a hyperlinks which looks like a

report.aspx&page=1 report.aspx&page=2 etc

How could I implemente a keyboard shortcuts so I could go forward to next page and to previos page by just holding CTRL and pressing either left arrow or right arrow.

I have seen a same functionality is implemented on some discussion boards, but can't figure out how to do it.

+1  A: 

See http://www.artlebedev.com/tools/technogrette/js/arrow-navigation/

<link rel="prev" href="report.aspx&page=1" id="PrevLink" />
<link rel="next" href="report.aspx&page=2" id="NextLink" />

. . .

<script language="javascript" type="text/javascript">
document.onkeydown = NavigateThrough;

function NavigateThrough (event)
{
  if (!document.getElementById) return;

  if (window.event) event = window.event;

  if (event.ctrlKey)
  {
    var link = null;
    switch (event.keyCode ? event.keyCode : event.which ? event.which : null)
    {
      case 0x25:
        link = document.getElementById ('PrevLink');
        break;
      case 0x27:
        link = document.getElementById ('NextLink');
        break;
    }

    if (link && link.href) document.location = link.href;
  }   
}
</script>
Pavel Chuchuva
Does not seem to be working in IE8: keyCode is null or not an object.
AlexKelos
Oops, apparently this line is required: if (window.event) event = window.event; I updated example from http://img.artlebedev.ru/svalka/navigate.js
Pavel Chuchuva