如何禁止小白查看网页源代码的简单操作

网友投稿 795 2022-05-29

所谓查看源代码,就是别人服务器发送到浏览器的原封不动的代码。

审查元素时,你看到那些,在源代码中找不到的代码,是在浏览器执行js动态生成的。

通过审查元素看到的就是最终的html代码。即:源代码 + 网页js渲染 。

我们查看网页源代码平时使用的方式是

1、右击鼠标,点击查看网页源代码。

2、按F12、ctrl+u、ctrl+shift+I、ctrl+shift+c查看源代码。

3、按ctrl+s保存下来,看源代码

4、XXXXX

屏蔽掉右键、复制、选择的完整代码:

首先我们来解决鼠标右击事件,就是我们自己实现右击事件,并且在右击事件函数里什么都不做。这样就弹不出右击菜单了。

/**禁止右击事件菜单弹出*/ document.οncοntextmenu=ContextMenu; function ContextMenu() { return false; }

1

2

3

4

5

6

其次,我们禁止使用ctrl+s、ctrl+u、F12、ctrl+shift+I、ctrl+shift+c。代码如下:

/** 全局事件监听*/ document.body.onkeydown = function(e){ var keyCode = e.keyCode || e.which || e.charCode; var ctrlKey = e.ctrlKey || e.metaKey; if(ctrlKey && (keyCode == 83 || keyCode == 85 || keyCode == 73)) { e.preventDefault(); return false; } else if(ctrlKey && (keyCode == 83 || keyCode == 85 || keyCode == 67)) { e.preventDefault(); return false; }else if(keyCode && keyCode == 123){ return false; } }

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

只要在你的初始化函数里加上上面的代码,那么你的页面就不能查看源代码了。当然只限于前三种方式。真正能实现源代码屏蔽的单纯的.html是不可能的!想看源代码也是没办法阻止的。此脚本这只能防止不劳而获的小白,针对计算机老鸟、大神是无法作用的;并且现在很多浏览器自带有查看网页源代码的功能。用TELEPROT 这类网站下载工具可以下载任何文件,相当于做镜像网站。想真正的保护源代码,除非服务器进行安全设置、加密。

js 里面的键盘事件经常用到的 记录一下

keyCode 8 = BackSpace BackSpace

keyCode 9 = Tab Tab

keyCode 12 = Clear

keyCode 13 = Enter

keyCode 16 = Shift_L

keyCode 17 = Control_L

keyCode 18 = Alt_L

keyCode 19 = Pause

keyCode 20 = Caps_Lock

keyCode 27 = Escape Escape

keyCode 32 = space

keyCode 33 = Prior

keyCode 34 = Next

keyCode 35 = End

keyCode 36 = Home

keyCode 37 = Left

keyCode 38 = Up

keyCode 39 = Right

keyCode 40 = Down

keyCode 41 = Select

keyCode 42 = Print

keyCode 43 = Execute

keyCode 45 = Insert

keyCode 46 = Delete

keyCode 47 = Help

keyCode 48 = 0 equal braceright

keyCode 49 = 1 exclam onesuperior

keyCode 50 = 2 quotedbl twosuperior

keyCode 51 = 3 section threesuperior

keyCode 52 = 4 dollar

keyCode 53 = 5 percent

keyCode 54 = 6 ampersand

keyCode 55 = 7 slash braceleft

keyCode 56 = 8 parenleft bracketleft

keyCode 57 = 9 parenright bracketright

keyCode 65 = a A

keyCode 66 = b B

keyCode 67 = c C

keyCode 68 = d D

keyCode 69 = e E EuroSign

keyCode 70 = f F

keyCode 71 = g G

keyCode 72 = h H

keyCode 73 = i I

keyCode 74 = j J

keyCode 75 = k K

keyCode 76 = l L

keyCode 77 = m M mu

keyCode 78 = n N

keyCode 79 = o O

keyCode 80 = p P

keyCode 81 = q Q at

keyCode 82 = r R

keyCode 83 = s S

keyCode 84 = t T

keyCode 85 = u U

keyCode 86 = v V

keyCode 87 = w W

keyCode 88 = x X

keyCode 89 = y Y

keyCode 90 = z Z

keyCode 96 = KP_0 KP_0

keyCode 97 = KP_1 KP_1

keyCode 98 = KP_2 KP_2

keyCode 99 = KP_3 KP_3

keyCode 100 = KP_4 KP_4

keyCode 101 = KP_5 KP_5

keyCode 102 = KP_6 KP_6

keyCode 103 = KP_7 KP_7

keyCode 104 = KP_8 KP_8

keyCode 105 = KP_9 KP_9

keyCode 106 = KP_Multiply KP_Multiply

keyCode 107 = KP_Add KP_Add

keyCode 108 = KP_Separator KP_Separator

如何禁止小白查看网页源代码的简单操作

keyCode 109 = KP_Subtract KP_Subtract

keyCode 110 = KP_Decimal KP_Decimal

keyCode 111 = KP_Divide KP_Divide

keyCode 112 = F1

keyCode 113 = F2

keyCode 114 = F3

keyCode 115 = F4

keyCode 116 = F5

keyCode 117 = F6

keyCode 118 = F7

keyCode 119 = F8

keyCode 120 = F9

keyCode 121 = F10

keyCode 122 = F11

keyCode 123 = F12

keyCode 124 = F13

keyCode 125 = F14

keyCode 126 = F15

keyCode 127 = F16

keyCode 128 = F17

keyCode 129 = F18

keyCode 130 = F19

keyCode 131 = F20

keyCode 132 = F21

keyCode 133 = F22

keyCode 134 = F23

keyCode 135 = F24

keyCode 136 = Num_Lock

keyCode 137 = Scroll_Lock

keyCode 187 = acute grave

keyCode 188 = comma semicolon

keyCode 189 = minus underscore

keyCode 190 = period colon

keyCode 192 = numbersign apostrophe

keyCode 210 = plusminus hyphen macron

keyCode 211 =

keyCode 212 = copyright registered

keyCode 213 = guillemotleft guillemotright

keyCode 214 = masculine ordfeminine

keyCode 215 = ae AE

keyCode 216 = cent yen

keyCode 217 = questiondown exclamdown

keyCode 218 = onequarter onehalf threequarters

keyCode 220 = less greater bar

keyCode 221 = plus asterisk asciitilde

keyCode 227 = multiply division

keyCode 228 = acircumflex Acircumflex

keyCode 229 = ecircumflex Ecircumflex

keyCode 230 = icircumflex Icircumflex

keyCode 231 = ocircumflex Ocircumflex

keyCode 232 = ucircumflex Ucircumflex

keyCode 233 = ntilde Ntilde

keyCode 234 = yacute Yacute

keyCode 235 = oslash Ooblique

keyCode 236 = aring Aring

keyCode 237 = ccedilla Ccedilla

keyCode 238 = thorn THORN

keyCode 239 = eth ETH

keyCode 240 = diaeresis cedilla currency

keyCode 241 = agrave Agrave atilde Atilde

keyCode 242 = egrave Egrave

keyCode 243 = igrave Igrave

keyCode 244 = ograve Ograve otilde Otilde

keyCode 245 = ugrave Ugrave

keyCode 246 = adiaeresis Adiaeresis

keyCode 247 = ediaeresis Ediaeresis

keyCode 248 = idiaeresis Idiaeresis

keyCode 249 = odiaeresis Odiaeresis

keyCode 250 = udiaeresis Udiaeresis

keyCode 251 = ssharp question backslash

keyCode 252 = asciicircum degree

keyCode 253 = 3 sterling

keyCode 254 = Mode_switch

使用event对象的keyCode属性判断输入的键值

eg:if(event.keyCode==13)alert(“enter!”);

键值对应表

A  0X65  U   0X85

B  0X66  V   0X86

C  0X67  W   0X87

D  0X68  X   0X88

E  0X69  Y   0X89

F  0X70  Z   0X90

G  0X71  0   0X48

H  0X72  1   0X49

I  0X73  2   0X50

J  0X74  3   0X51

K  0X75  4   0X52

L  0X76  5   0X53

M  0X77  6   0X54

N  0X78  7   0X55

O  0X79  8   0X56

P  0X80  9   0X57

Q  0X81 ESC  0X1B

R  0X82 CTRL  0X11

S  0X83 SHIFT 0X10

T  0X84 ENTER 0XD

Keycode常数表

可在代码中的任何地方用下列常数代替实际值:

常数 值 描述

vbKeyLButton 0x1 鼠标左键

vbKeyRButton 0x2 鼠标右键

vbKeyCancel 0x3 CANCEL 键

vbKeyMButton 0x4 鼠标中键

vbKeyBack 0x8 BACKSPACE 键

vbKeyTab 0x9 TAB 键

vbKeyClear 0xC CLEAR 键

vbKeyReturn 0xD ENTER 键

vbKeyShift 0x10 SHIFT 键

vbKeyControl 0x11 CTRL 键

vbKeyMenu 0x12 MENU 键

vbKeyPause 0x13 PAUSE 键

vbKeyCapital 0x14 CAPS LOCK 键

vbKeyEscape 0x1B ESC 键

vbKeySpace 0x20 SPACEBAR 键

vbKeyPageUp 0x21 PAGE UP 键

vbKeyPageDown 0x22 PAGE DOWN 键

vbKeyEnd 0x23 END 键

vbKeyHome 0x24 HOME 键

vbKeyLeft 0x25 LEFT ARROW 键

vbKeyUp 0x26 UP ARROW 键

vbKeyRight 0x27 RIGHT ARROW 键

vbKeyDown 0x28 DOWN ARROW 键

vbKeySelect 0x29 SELECT 键

vbKeyPrint 0x2A PRINT SCREEN 键

vbKeyExecute 0x2B EXECUTE 键

vbKeySnapshot 0x2C SNAPSHOT 键

vbKeyInsert 0x2D INSERT 键

vbKeyDelete 0x2E DELETE 键

vbKeyHelp 0x2F HELP 键

vbKeyNumlock 0x90 NUM LOCK 键

A 至 Z 键与 A – Z 字母的 ASCII 码相同:

常数 值 描述

vbKeyA 65 A 键

vbKeyB 66 B 键

vbKeyC 67 C 键

vbKeyD 68 D 键

vbKeyE 69 E 键

vbKeyF 70 F 键

vbKeyG 71 G 键

vbKeyH 72 H 键

vbKeyI 73 I 键

vbKeyJ 74 J 键

vbKeyK 75 K 键

vbKeyL 76 L 键

vbKeyM 77 M 键

vbKeyN 78 N 键

vbKeyO 79 O 键

vbKeyP 80 P 键

vbKeyQ 81 Q 键

vbKeyR 82 R 键

vbKeyS 83 S 键

vbKeyT 84 T 键

vbKeyU 85 U 键

vbKeyV 86 V 键

vbKeyW 87 W 键

vbKeyX 88 X 键

vbKeyY 89 Y 键

vbKeyZ 90 Z 键

0 至 9 键与数字 0 – 9 的 ASCII 码相同:

常数 值 描述

vbKey0 48 0 键

vbKey1 49 1 键

vbKey2 50 2 键

vbKey3 51 3 键

vbKey4 52 4 键

vbKey5 53 5 键

vbKey6 54 6 键

vbKey7 55 7 键

vbKey8 56 8 键

vbKey9 57 9 键

下列常数代表数字键盘上的键:

常数 值 描述

vbKeyNumpad0 0x60 0 键

vbKeyNumpad1 0x61 1 键

vbKeyNumpad2 0x62 2 键

vbKeyNumpad3 0x63 3 键

vbKeyNumpad4 0x64 4 键

vbKeyNumpad5 0x65 5 键

vbKeyNumpad6 0x66 6 键

vbKeyNumpad7 0x67 7 键

vbKeyNumpad8 0x68 8 键

vbKeyNumpad9 0x69 9 键

vbKeyMultiply 0x6A MULTIPLICATION SIGN (*) 键

vbKeyAdd 0x6B PLUS SIGN (+) 键

vbKeySeparator 0x6C ENTER 键

vbKeySubtract 0x6D MINUS SIGN (-) 键

vbKeyDecimal 0x6E DECIMAL POINT (.) 键

vbKeyDivide 0x6F DIVISION SIGN (/) 键

下列常数代表功能键:

常数 值 描述

vbKeyF1 0x70 F1 键

vbKeyF2 0x71 F2 键

vbKeyF3 0x72 F3 键

vbKeyF4 0x73 F4 键

vbKeyF5 0x74 F5 键

vbKeyF6 0x75 F6 键

vbKeyF7 0x76 F7 键

vbKeyF8 0x77 F8 键

vbKeyF9 0x78 F9 键

vbKeyF10 0x79 F10 键

vbKeyF11 0x7A F11 键

vbKeyF12 0x7B F12 键

vbKeyF13 0x7C F13 键

vbKeyF14 0x7D F14 键

vbKeyF15 0x7E F15 键

vbKeyF16 0x7F F16 键

网站

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:初识MySQL之概念认识篇
下一篇:【月更第14天】Python爬虫工程师必备工具 Charles 的安装,以及爬取淘宝网+学UI网
相关文章