Solved

Using Page up/Down Buttons

Posted on 1998-07-28
5
1,620 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

689 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