Keyboard Next/Prev Navigation
Permalink
How would I go about implementing on keypress activation for the next/prev block? I looked for some examples online on how you can do this and the simplest way seems to be through a javascript script like the following.
How could I go about implementing this into the next/prev links? Any help is greatly appreciated.
edit:
This would be more useful I think.
document.onkeyup = KeyCheck; function KeyCheck(e) { var KeyID = (window.event) ? event.keyCode : e.keyCode; switch(KeyID) { case 49: window.location = "index.html"; break; } }
How could I go about implementing this into the next/prev links? Any help is greatly appreciated.
edit:
This would be more useful I think.
$(window.document).keydown(function(e) { var code = e.keyCode; if (code == 37 || code == 75) { $('#load-prev').click(); } else if (code == 39 || code == 74) { $('#load-next').click(); } });
Got it to work. Slightly differently but it works no less as I couldn't get .click() to work or any other solution that was on google except for this one.
Once you are happy that it is a reliable solution, maybe package it up as an add-on.
Start with your second bit of code. Using jQuery it has already sorted out all the browser differences on keyboard events.
Create a custom view for the next/prev block, add a <script> section at the end of it, and put the jQuery in. Adapt the #load selectors to match the id of the next/prev buttons or links. Then on your page insert the next/prev block and use the custom view.