鑒於安全性的考慮,不少網站在登錄輸入密碼時都采用了軟鍵盤,避免一些鍵盤記錄工具和木馬對擊鍵的捕捉。項目中也有這個需求,就分享給大家了,貼個效果圖上來。。有興趣的朋友可以收藏。。..如果覺得功能有點龐大,只需要數字小鍵盤的朋友,可參考代碼精簡。
下載大鍵盤: http://www.cnblogs.com/Files/sccxszy/softKey.rar
小鍵盤:http://www.cnblogs.com/Files/sccxszy/smallSoftkey.rar
效果還原:Default.aspx,softkeyboard.js,softkey.CSS三個文件
js代碼:
softkeyboard.js
1window.onload=
2function()
3{
4password1=null;
5initCalc();
6}
7var password1;
8var CapsLockValue=0;
9var checkSoftKey;
10function setVariables() {
11tablewidth=630;
12tableheight=20;
13if (navigator.appName == "Netscape") {
14horz=".left";
15vert=".top";
16docStyle="document.";
17styleDoc="";
18innerW="window.innerWidth";
19innerH="window.innerHeight";
20offsetX="window.pageXOffset";
21offsetY="window.pageYOffset";
22}
23else {
24horz=".pixelLeft";
25vert=".pixelTop";
26docStyle="";
27styleDoc=".style";
28innerW="document.body.clientWidth";
29innerH="document.body.clientHeight";
30offsetX="document.body.scrollLeft";
31offsetY="document.body.scrollTop";
32}
33}
34function checkLocation() {
35if (checkSoftKey) {
36objectXY="softkeyboard";
37var availableX=eval(innerW);
38var availableY=eval(innerH);
39var currentX=eval(offsetX);
40var currentY=eval(offsetY);
41x=availableX-tablewidth+currentX;
42y=currentY;
43evalMove();
44}
45setTimeout("checkLocation()",0);
46}
47function evalMove() {
48eval(docStyle + objectXY + styleDoc + vert + "=" + y);
49}
50self.onError=null;
51currentX = currentY = 0;
52whichIt = null;
53lastScrollX = 0; lastScrollY = 0;
54NS = (document.layers) ? 1 : 0;
55IE = (document.all) ? 1: 0;
56function heartBeat() {
57if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }
58if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }
59if(diffY != lastScrollY) {
60percent = .1 * (diffY - lastScrollY);
61if(percent > 0) percent = Math.ceil(percent);
62else percent = Math.floor(percent);
63if(IE) document.all.softkeyboard.style.pixelTop += percent;
64if(NS) document.softkeyboard.top += percent;
65lastScrollY = lastScrollY + percent;}
66if(diffX != lastScrollX) {
67percent = .1 * (diffX - lastScrollX);
68if(percent > 0) percent = Math.ceil(percent);
69else perce