JS 右クリック/コピー/貼り付け/キーボードを禁止

  • 作成者:ayuan0625
  • 編集回数:15次
  • 最終更新:ayuan0625 于 2020-12-15
  • I. Disable right click

    After logging in to the system, the user can view the URL and then access it by clicking the properties on right-click menu. If you want to enhance security and restrict users from viewing the URL, you can disable right-click menu.

    Click Template>Template Web Attributes>Pagination preview , select "individually set for this template", add a "loading end" event using following JS:

    function nocontextmenu(event){
    event = event || window.event;
    if (event.which == 2 )
    event.returnValue = false;
    return false;
    }
    document.oncontextmenu = nocontextmenu;

    The basic principle of this code is to return false when the user's page event is the right click (event.which == 2), and the pop-up menu is disabled.

    If there is a parameter panel in the template, and you want to disable the right button as soon as the report is shown, instead of after querying, you need to add an initialization event to the query button of the parameter panel and write the above JavaScript code.

    Note: If you want to disable the right-click operation on data analysis preview or data entry preview, do the same settings in the template>template web attributes on corresponding preview page setting.


    II. Disable copy, paste and cut

    For disabling copy function, click Template>Template Web Attributes>Pagination preview , select "individually set for this template", add a "loading end" event using following JS:

    1.png

    document.oncopy=function(e) {  
       alert('Cannot copy currently!');  
       return false;  
    }

    For disabling other functions, please refer to the table below:

    Function
    Method
    Selection

    document.onselectstart  

    Copy

    document. oncopy

    Cut

    document. oncut  

    Paste

    document. onpaste  

    III. Disable keyboard events

    For monitoring user keyboard events by passing the event object, such as prohibiting the enter key function, click Template>Template Web Attributes>Pagination preview , select "individually set for this template", add a "loading end" event using following JS:

    2.png

    function test(event){
     if(event.keyCode == 13){
    alert("The enter key cannot be used!");
    return false;
    }else{
    return true;
    }
    }
    Document.onkeydown =test;

    For more keycode, please Google search ASCII.

    Attachment List


    Theme: FineReport カスタム開発
    • いいね
    • 良くない
    • 閲覧しただけ