標籤

4GL (1) 人才發展 (10) 人物 (3) 太陽能 (4) 心理 (3) 心靈 (10) 文學 (31) 生活常識 (14) 光學 (1) 名句 (10) 即時通訊軟體 (2) 奇狐 (2) 爬蟲 (1) 音樂 (2) 產業 (5) 郭語錄 (3) 無聊 (3) 統計 (4) 新聞 (1) 經濟學 (1) 經營管理 (42) 解析度 (1) 遊戲 (5) 電學 (1) 網管 (10) 廣告 (1) 數學 (1) 機率 (1) 雜趣 (1) 證券 (4) 證券期貨 (1) ABAP (15) AD (1) agentflow (4) AJAX (1) Android (1) AnyChart (1) Apache (14) BASIS (4) BDL (1) C# (1) Church (1) CIE (1) CO (38) Converter (1) cron (1) CSS (23) DMS (1) DVD (1) Eclipse (1) English (1) excel (5) Exchange (4) Failover (1) Fedora (1) FI (57) File Transfer (1) Firefox (3) FM (2) fourjs (1) Genero (1) gladiatus (1) google (1) Google Maps API (2) grep (1) Grub (1) HR (2) html (23) HTS (8) IE (1) IE 8 (1) IIS (1) IMAP (3) Internet Explorer (1) java (4) JavaScript (22) jQuery (6) JSON (1) K3b (1) ldd (1) LED (3) Linux (117) Linux Mint (4) Load Balance (1) Microsoft (2) MIS (2) MM (51) MSSQL (1) MySQL (27) Network (1) NFS (1) Office (1) OpenSSL (1) Oracle (126) Outlook (3) PDF (6) Perl (60) PHP (33) PL/SQL (1) PL/SQL Developer (1) PM (3) Postfix (2) postfwd (1) PostgreSQL (1) PP (50) python (5) QM (1) Red Hat (4) Reporting Service (28) ruby (11) SAP (234) scp (1) SD (16) sed (1) Selenium (3) Selenium-WebDriver (5) shell (5) SQL (4) SQL server (8) sqlplus (1) SQuirreL SQL Client (1) SSH (2) SWOT (3) Symantec (2) T-SQL (7) Tera Term (2) tip (1) tiptop (24) Tomcat (6) Trouble Shooting (1) Tuning (5) Ubuntu (37) ufw (1) utf-8 (1) VIM (11) Virtual Machine (2) VirtualBox (1) vnc (3) Web Service (2) wget (1) Windows (19) Windows (1) WM (6) Xvfb (2) youtube (1) yum (2)

2013年7月6日 星期六

Disable Print Screen Key and All Keyboard Keys by JavaScript

http://www.codeproject.com/Articles/37292/Disable-Print-Screen-Key-and-All-Keyboard-Keys-in

Introduction

In this article, I will explain how to disable print screen or keyboard in secure applications as Exam online in E-learning system or in any application you want to protect.
Some people can hack your data by using print screen, take HTML source code or even print the questions.
We have 4 challenges to create pages for exams or secure application:
  1. Disable print screen and clear any Clipboard data
  2. Avoid using keyboard or mouse
  3. Hide data in HTML source 
  4. Avoid using print page
The first step is to avoid using print screen key
To solve this problem you have to access the user’s clipboard by JavaScript function:
<script language="javascript" type="text/javascript">
    function AccessClipboardData() {
        try {
    window.clipboardData.setData('text', "No print data");
        } catch (err) {
   txt = "There was an error on this page.\n\n";
   txt += "Error description: " + err.description + "\n\n";
   txt += "Click OK to continue.\n\n";
    alert(txt);
        }
    }
</script>
This function clears any clipboard object and sets a new clipboard in a message as the previous example.
If the user presses print screen key, he or she cannot capture any image because the clipboard contains a text message that says "No print data". So don't forget to close this page if you would like to copy a text or a file in your operating system.
We call this function(AccessClipboardData) every 300 milliseconds by using setInterval to clear any object in clipboard.
 setInterval("AccessClipboardData()", 300);
But this solution not complete because Internet Explorer will ask the user if he/she will allow this page to access the clipboard or not. So we have to write code to handle this option if the user will not allow the page to access the clipboard.
Add this code after the setInterval function:
setInterval("AccessClipboardData()", 300);
var ClipBoardText = "";
         if (window.clipboardData) {
             ClipBoardText = window.clipboardData.getData('text');
             if (ClipBoardText != "No print data") {
               alert('Sorry you have to allow the page to access clipboard');
// hide the div which contains your data          
document.all("divmaster").style.display = "none"
             }
In the previous code, we declare a clipboardtext variable to get clipboard text and check if the user allows the page to access the clipboard or not.
The second step is to avoid using keyboard
To solve this problem, you have to capture all events and cancel them by pop messages in case of copying data by CTRL+C or select all data by CTRL+A.
document.onkeydown = function(ev) {
  var a;
   ev = window.event;
   if (typeof ev == "undefined") {
     alert("PLEASE DON'T USE KEYBORD");
          }
       a = ev.keyCode;
        alert("PLEASE DON'T USE KEYBORD");
              return false;
         }
       document.onkeyup = function(ev) {
           var charCode;
        if (typeof ev == "undefined") {
         ev = window.event;
         alert("PLEASE DON'T USE KEYBORD");
           } else {
          alert("PLEASE DON'T USE KEYBORD");
           }
         return false;
       }
The third step is to avoid using print page
To solve this problem, you have to use CSS (Cascade Style Sheet) to hide your data in printing:
<style type="text/css" media="print">
.noprint {
display: none;
}
</
Finally we want to avoid data from appearing in the HTML source, so we will use update panel and if your data gets in page_load event delay shows data by timer control.

沒有留言:

張貼留言