Completely blocked right-click

Source: Internet
Author: User

As we all know, to protect a page, the most basic thing is to shield right-click. The most commonly used function click () on a webpage is the following section.Code:

<SCRIPT>
Function click (){
If (event. Button = 2 ){
Alert ('Welcome to this website !! ');
}
}
Document. onmousedown = click
</SCRIPT>

However, this blocking method is also well known. That is, you can click the left mouse button and right-click to view the right-click menu. However, I have seen a good method of blocking right-click. Its principles are different from those mentioned above. It is not a script written in JS, but a restriction to define webpage attributes. In addition, JavaScript scripts should be avoided as much as possible during blocking. As long as the browser disables the Javascript script in IE. All blocking is in vain.

In this case, we will continue to use the method of modifying the webpage attribute to shield right-click the webpage. This method uses the <body> in HTML for modification. It has only one line of code:

<Body oncontextmenu = "self. event. returnvalue = false">

Oncontextmenu is defined here. If the right-click value is false, the right-click is blocked. Now, try again to hack the attack method just now. You can no longer right-click the shortcut menu when you press the Left or Right button. No, but try other methods. No matter how messy you are, right-clicking is useless. Because the right-click does not exist on this webpage. What can you do for a nonexistent function key?

However, blocking the right-click operation does not solve the problem. If I want to copy a text clip or an image. Then, press Ctrl + C and press Ctrl + V to copy and paste it. By the way, what we will talk about next is to shield the left button (what? Shield left button? So this web page is almost useless? Don't worry. If you don't finish it, it's annoying to leave only one function.

As mentioned above, it is useless to use js to block the website and to eliminate the symptoms. Then, we can use HTML, the most basic language of the web page. Define <body>. The parameter used this time is onselectstart. Is the left-click selected parameter. The Code is as follows:

<Body onselectstart = "Return false">

In this way, the left-click selection function is easily blocked. The principle is the same as above. Now, it is useless to select any content with your left-click. Naturally, you cannot press Ctrl + C or Ctrl + v. Now let's merge the two parts. Completely control the left and right keys! :

<Body oncontextmenu = "self. event. returnvalue = false" onselectstart = "Return false">

Now, the left and right keys are solved.

 

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.