Keyboard shortcuts for browsing pages of lists

If you want to add keyboard shortcut (right and left arrow keys) to navigate between a list of pages then use javascript code below.

// Keyboard shortcuts for browsing pages of lists
$(document).keydown(handleKey);
function handleKey(e){
var left_arrow = 37;
var right_arrow = 39;
if (e.target.localName == 'body' || e.target.localName == 'html'){
if (!e.ctrlKey && !e.altKey && !e.shiftKey && !e.metaKey){
var code = e.which;
if (code == left_arrow)
prevPage();
else if (code == right_arrow)
nextPage();
}
}
}
function prevPage(){
var href = $('.pageslist .prev').attr('href');
if (href && href != document.location)
document.location = href;
}
function nextPage(){
var href = $('.pageslist .next').attr('href');
if (href && href != document.location)
document.location = href;
}

To use js code your html code looks like:

Leave a comment