Blue Ridge Software LLC
  Encryption
Services
  Webmaster
Services
  Programming   Software   About Us

Program Snippets

  Javascript - Arrow Key Navigation (Add To Favorites)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> Arrow Key Demonstration </title>
  <meta name="Generator" content="EditPlus V3.31">
  <meta name="Author" content="D Waterfield, Blue Ridge Software LLC">
  <meta name="Keywords" content="javascript, arrow key nav, arrow key, navigation">
  <meta name="Description" content="Short demonstration of arrow key and/or mouse navigation using straight javascript">
 </head>

 <body>
  <form name="frm">
  <input type="hidden" name="prev">
  <input type="hidden" name="next">
  <script type="text/javascript">
  <!--
		var page = getQueryVariable("page");
		var p = parseInt(page);
		if((p>0) && (p<15)) {
			//alert("you are on page " + p.toString());
		}

		function leftArrowPressed() {
			var page = getQueryVariable("page");
			if (page=="")
			{
				page = "1";
			}
			var p = parseInt(page);

			if (page=="0") {
				p=2;
			}
			p = p - 1;
			if (p==0) {
				p=14;
			}
			//alert("you pressed left arrow");			
			window.location = "ArrowKeyNavigation.html?page=" + p.toString();
		}

		function rightArrowPressed() {
			var page = getQueryVariable("page");
			if (page=="")
			{
				page = "0";
			}

			var p = parseInt(page);

			if (page=="14") {
				p=0;
			}
			p = p + 1;
			if (p==15) {
				p=1;
			}
			//alert("you pressed right arrow");
			window.location = "ArrowKeyNavigation.html?page=" + p.toString();
		}
				
		function getQueryVariable(variable)
		{
			   var query = window.location.search.substring(1);
			   var vars = query.split("&");
			   for (var i=0;i<vars.length;i++) {
					   var pair = vars[i].split("=");
					   if(pair[0] == variable){return pair[1];}
			   }
			   return(false);
		}

		document.onkeydown = function(evt) {
			evt = evt || window.event;
			switch (evt.keyCode) {
				case 37:
					leftArrowPressed();
					break;
				case 39:
					rightArrowPressed();
					break;
			}
		};

		var tmpp = p;
		var prev = tmpp - 1;
		if (prev<=0) {
			prev=14;
		}
		var next = tmpp + 1;
		if (next>=15) {
			next=1;
		}

		document.frm.prev.value=prev;
		document.frm.next.value=next;

		document.write("<a id='prevlink' href='ArrowKeyNavigation.html?page=" + document.frm.prev.value + "'>");
		document.write("prev");
		document.write("</a>&nbsp;");

		document.write("<a id='nextlink' href='ArrowKeyNavigation.html?page=" + document.frm.next.value + "'>");
		document.write("next");
		document.write("</a>");

	//-->
	</script>
  </form>
 </body>
</html>
© 2013- Blue Ridge Software LLC