Forum Moderators: open

Message Too Old, No Replies

Press Spacebar to Open Page

         

potentialgeek

10:48 pm on Sep 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I couldn't believe I couldn't find the script for this via Google!

What's the code which works in all the major browsers that lets users open the next page in a series of pages by simply pressing Spacebar (instead of clicking on a 'Next' link)?

I got the idea from Opera which has a 'Smart spacebar.'

Script Summary: When page is scrolled to bottom, press spacebar to go to next page in list.

Pressing spacebar scrolls page as usual, but if there's nothing left to scroll, it goes to the next page. Link to next page is determined by rel="next" attribute or by link text.

lostdreamer

9:21 am on Sep 14, 2011 (gmt 0)

10+ Year Member



If you are using jQuery on your page it is pretty easy:



$("*").keypress(function(e) {
if(e.which == 32) {
// hit spacebar
belowFold = $("html").height() - $(window).height() - $("html").scrollTop();
if(belowFold < 1 && $("a[rel=next]").size() > 0) {
location.href = $("a[rel=next]").attr('href');
}
}
});