How to prohibit others from viewing website source code in JS:
View the effect: click it.
1. Directly press F12
2. Ctrl + Shift + I view
3. Right-click to view
4. Ctrl + u = view-source: + url
You can simply block all the above three states. The document has an onkeydown (Keyboard button event), and the corresponding keycode can be found in the event and processed,
Document also has an oncontextmenu right-click event to block it. 4. the Ctrl + u can be blocked. [However, if you add view-source before the URL, refresh it and you can still see it. ^_^]
The JS verification code is as follows:
Window. onload = function () {document. onkeydown = function () {var e = window. event | arguments [0]; if (e. keyCode = 123) {alert ("what do you want? "); Return false;} else if (e. ctrlKey) & (e. shiftKey) & (e. keyCode = 73) {alert ("is not displayed for you .. "); Return false;} else if (e. ctrlKey) & (e. keyCode = 85) {// append return false ;}}; document. oncontextmenu = function () {alert ("this is not for you"); return false ;}}