views:

309

answers:

1

I've been search the WWW for a while and can't seem to see what I'm looking for... I need a piece of code that will allow my page to move on when someone uses the arrow keys to move forward or back. PLEASE HELP! THANKS... :)

+1  A: 

Add an event listener to your window that traps the onkeyup event. Then find the keycode for the arrow key left and arrow key right (this will be an integer), and call history.back() for a left arrow or history.forward() for a right arrow value.

Robusto
There’s also a convention of using `<link rel="next" src="URL_OF_NEXT_PAGE_HERE" />` in your `<head>` tag to indicate the next/previous pages in a sequence if “back” doesn’t necessarily mean “the last page in the user’s browser history”. You could read out those values and use them instead of `history.forward()` etc. See e.g. http://diveintohtml5.org/semantics.html#new-relations
Paul D. Waite