/ Published in: JavaScript
Starting with GoogleTV in mind I made a script to help navigate a page key basic key inputs, in this case I'm using the left and right arrows to jump between the H1 tags on a page, although the modifications to make it do other things would be very simple. Theres a more working concept on the link so you can see it in action without any coding on your part (and participate in some proper reading).
There is one downside to this method, if manually scrolling down past an H1 tag it does not realize it, but I'll work on that once I get a chance
There is one downside to this method, if manually scrolling down past an H1 tag it does not realize it, but I'll work on that once I get a chance
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function keycatch(){ var keypress = event.keyCode var h1tags = document.body.getElementsByTagName("h1"); switch(keypress){ case 37: // Left if(currentpos!=0){ currentpos = currentpos-1; h1tags[currentpos].scrollIntoView(); } return false break; case 39: // Right if(h1tags[currentpos+1]!=undefined){ currentpos = currentpos+1; h1tags[currentpos].scrollIntoView(); } return false break; } }
URL: http://fatfolderdesign.com/125/code/working-with-javascript-key-input