How does JS prohibit others from viewing website source code?

Source: Internet
Author: User
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 ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.