Do not use the right key to view source code

Source: Internet
Author: User
Tags key
Right Key | Source code to do the Web page friends will encounter this situation: sometimes their own hard day to do the Web page, especially some JavaScript effects, it is easy to be used to view the source file and copy. So how can you prevent people from viewing the source code? We can use the Event.button feature to do it. The following table is the possible value and meaning of the Event.button property:
0 No buttons.
1 Press left button
2 Press the right button
3 Press left and right key
4 Press the Middle key
5 press left and middle key
6 Press right and middle key
7 Press All the keys
Referring to the table above, we can add the following statement between <body> and </body>:
<script langvage=javascript>
function Click () {
if (event.button!=1) {alert (' Copyright (C) 2001 XXX Studio ');
}}
Document.onmousedown=click;
</Script>
In this way when browsing the Web page, in addition to the left mouse button, any other form of mouse click or combination of clicks, will appear "Copyright (C) 2004 Web Teaching Network" prompt box, rather than appear shortcut menu, so as to avoid being viewed source file code.
If you make event.button=2, in fact, it can only limit the right mouse click situation, other clicks, such as press the left key, press the left-hand and middle key, press the middle key, etc. can not be limited, when the click occurred in these ways, the shortcut menu appears, so you can view the source file.

PostScript: Personal wisdom is limited after all, do a Web page to learn from others is a good way, but must be allowed by the original author Oh, otherwise he may be the way described above to deal with you.

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.