I'm making a gallery and trying to figure out how to program the arrow keys to navigate the gallery.
So, pressing the left arrow would go to the previous image url:
function window.location = 'http://www.example.com/prevphoto.php';
Pressing the right arrow would go to the next image url.
function window.location = 'http://www.example.com/nextphoto.php';
Update (Thanks Haxxed pointing me in the right direction) This is where I'm at, but it's not working. Can you see why?
$('body').keypress(function (e) {
if (e.which == 37) {
// Left Arrow Pushed
window.location = "/prevphoto.php";
} else if (e.which == 39) {
// Right Arrow Pushed
window.location = "/nextphoto.php";
}
});