Solved

Using Page up/Down Buttons

Posted on 1998-07-28
5
1,577 Views
Last Modified: 2012-06-27

I'm looking for a way to have javaScript capture the Page Up or Page Down button being pressed on my keyboard?  I would like to be able to call a javaScript function when this action takes place.  Is there any way to do this?
0
Comment
Question by:vanfleet
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
Quixote earned 50 total points
ID: 1267341
I am developing on a Mac, and the following works on Netscape 4 and not IE4, but it may work for the PC version of IE4 since Microsoft crippled the Mac version.  Nothing but version 4 browsers have the capability to sense key clicks.  Here's the code -- place it within script tags in the head of your document:

document.captureEvents(Event.KEYPRESS)
document.onkeypress = pageMove;
function pageMove(evnt)
   {
   if (evnt.which == 11)
      {
      // place your page-up code here
      }
   else if (evnt.which == 12)
      {
      // place your page-down code here
      }
   else
      {
      alert(evnt.which);  // for debugging: erase this line when it works
      return true;
      }
   }


In your code, returning true will allow the key press to proceed as normal (paging up or down), but if you want to replace that default function with your code, then return false.  You should always return true if it doesn't find what it's looking for, otherwise the user can't type.

The debugging line is in there because I wasn't sure if PC PageUp and PageDown is the same ASCII code as Mac PageUp and PageDown.  If PageUp is not 11 and PageDown is not 12, then you can write the script so that it checks the value and platform.

Do you mind me asking what you plan on doing with this?

0
 

Author Comment

by:vanfleet
ID: 1267342
This code is exactly what I'm looking for. However, It appears that the value for both PageUp and PageDown is 0, that's not much help, but there are other keys I can still use.  Also, I have the same problems with IE that you do, this code doesn't seem to work with IE on my NT machine ether, it all doesn't work at all on my Unix machine (with Netscape or IE).

To answer you question, I'm the system manager for a group that develops online training for a CAD/CAM product called Unigraphics.  I have thousands of HTML document all linked together and my plan is to use this code to let the user jump from one document to another with the keyboard.

Thanks for you help!
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1267343
That's pretty neat -- a keystroke to jump pages.  Sorry to hear that the ASCII code is different between platforms -- makes it tougher to do exactly this sort of this.

I had my suspicions that Netscape 4 would be the only one capable of this.  I've got a little page I slapped together for various tests in JavaScript:
http://www.wenet.net/~quixote/babble/JavaScriptTestor.html
Visit it with Netscape 4 on the various platforms and hit the keys you want to use: you should get a readout of what the ASCII code is.  Uses the same code I posted above to extract the keystroke.
0
 

Author Comment

by:vanfleet
ID: 1267344
I think what I'll do is use the spacebar (32) to goto the next page and backspace (8) to goto the previous page.  Do you get the same ACCII codes (32 and 8) on your machine?  

I went to your test site and tried the Page Up and Page Down button and got no responce at all, the others worked fine.

You can see a sample of this training material at:
http://www.ugsolutions.com/training/crv/crv/begin.html

Thanks Again, you've been a big help.
0
 
LVL 2

Expert Comment

by:Quixote
ID: 1267345
I'm at work now -- no Mac in sight to try.  I'll check tonight, but you'll have to tackle any Unix checking.  If it winds up being different ASCII, then I'll include some browser-sensing in the code to make it work for you.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Tag input html 4 38
connect a series of circles by line based on clicks 4 38
onOpen 14 41
Cordova Camera plugin fails 2 19
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now