Skip to content

Instantly share code, notes, and snippets.

@hkulekci
Created May 8, 2011 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkulekci/961314 to your computer and use it in GitHub Desktop.
Save hkulekci/961314 to your computer and use it in GitHub Desktop.
Page navigation with Javascript and no jquery
<html>
<head>
<title>Example Page</title>
</head>
<body>
<div id="text"></div>
<script type="text/javascript">
var urls = {
"37":"#previous-page",//left button
"39":"#next-page",//right button
"38":"#header",//top button
"40":"#comments",//bottom button
};
var log_h = function(string){
document.getElementById("text").innerHTML = string;
//window.location ...
}
var myKeyPressHandler = function(e) {
var unicode=e.keyCode? e.keyCode : e.charCode
if (urls[unicode] != undefined)
log_h(urls[unicode]);
}
document.onkeypress = myKeyPressHandler;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment