JS Using Keyboard to Turning Pages

  • Last update:  2020-12-28
  • I. Problem Description

    How to control the pages of a report by up and down keys in our keyboard just like we presenting a PowerPoint?

    II. Solution

    Each key in the keyboard has a unique key code. With JavaScript, we can obtain the key code of the pressed key, judge whether it is a up/down key, and then make the report jump to the previous/next page.

    III. Example

    Select Template > Web Attributes. Choose Pagination Preview, checkIndividually set for the template,  and add a Loading End event.

    image.png

    JS code:

    $(document).bind('keydown', function(e) { //Get key press event
    var key = window.event ? e.keyCode : e.which; //Get key code
    //alert(key);
    if (key.toString() == "33"|| key.toString() == "37" || key.toString() == "38") {
    contentPane.gotoPreviousPage(); //Jump to the previous page

    else if (key.toString() == "32" || key.toString() == "34"|| key.toString() == "39" || key.toString() == "40") {
    contentPane.gotoNextPage(); //Jump to the next page
    }
    })

    Key code table:

    Key
    Key code

    Space

    32

    Page Down(PgDn)

    34 

    Left Arrow(←)

    37  

    Up Arrow(↑)

    38  

    Right Arrow(→)

    39  

    Down Arrow(↓)

    40  

    Save report and select Pagination Preview, if click Page Up(PgUp), Left Arrow(←) or Up Arrow(↑), the page will jump to the previous page.

    Oppositely, if click Space, Page Down(PgDn), Right Arrow(→) or Down Arrow(↓), page can jump to the next page.

    IV. Completed template

    Attachment List


    Theme: Report Application
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy