Summary of practical javascript technology (1) Blocking

Source: Internet
Author: User
Summary of practical javascript technology (1) Blocking

1. Shield all keyboard keys
<Script language = "JavaScript">
<! --
Function document. onkeydown (){
Event. keycode = 0;
Event. returnvalue = false;
}
-->
</SCRIPT>

2. Right-click the screen

Add oncontextmenu = self. event. returnvalue = false or:
<Script language = "JavaScript">
<! --
Function document. oncontextmenu ()
{
Return false;
}
-->
</SCRIPT>
<Script language = JavaScript>
Function click (){
If (event. Button = 2 ){
Alert ('Sorry, this page cannot be copied! ')
}
}
Document. onmousedown = click
</SCRIPT>

Function nocontextmenu ()
{
If (document. All ){
Event. cancelbubble = true;
Event. returnvalue = false;
Return false;
}
}
Or:
<Body onmousedown = "rclick ()" oncontextmenu = "nocontextmenu ()">

<Script language = "JavaScript">
<! --
Function rclick ()
{
If (document. All ){
If (event. Button = 2 ){
Event. returnvalue = false;
}
}
}
-->
</SCRIPT>

3. Block Ctrl + N, Shift + F10, F5 refresh, and return keys
<Script language = "JavaScript">
<! --
// Shield right-click, CTRL + N, Shift + F10, F5 refresh, and backspace key
Function window. onhelp () {return false} // block F1 help
Function keydown (){
If (window. event. altkey )&&
(Window. event. keycode = 37) | // mask Alt + direction key seek
(Window. event. keycode = 39) {// mask Alt + direction key →
Alert ("You are not allowed to use Alt + arrow keys to move forward or backward the webpage! ");
Event. returnvalue = false;
}

Note: this does not really block Alt + direction keys, because when Alt + direction keys pop up a warning box, press and hold the Alt key, and drop the warning box with the mouse, this blocking method will become invalid.
If (event. keycode = 8 )&&
(Event. srcelement. type! = "Text "&&
Event. srcelement. type! = "Textarea "&&
Event. srcelement. type! = "Password") | // block the backspace deletion key
(Event. keycode = 116) | // block the F5 refresh key
(Event. ctrlkey & event. keycode = 82) {// Ctrl + R
Event. keycode = 0;
Event. returnvalue = false;
}
If (event. ctrlkey) & (event. keycode = 78) // block Ctrl + n
Event. returnvalue = false;
If (event. shiftkey) & (event. keycode = 121) // block SHIFT + F10
Event. returnvalue = false;
If (window. event. srcelement. tagname = "A" & window. event. shiftkey)

Window. event. returnvalue = false; // block shift with the left mouse button to open a new page
If (window. event. altkey) & (window. event. keycode = 115) {// block Alt + F4
Window. showmodelessdialog ("about: blank", "", "dialogwidth: 1px; dialogheight: 1px ");
Return false ;}
}

In addition, you can use window. Open to shield all IE menus.
Method 1:
Window. Open ("Your .htm", "", "toolbar = No, location = No, directories = No, menubar = No,
Scrollbars = No, resizable = Yes, status = No, top = 0, Left = 0 ")

The second method is to open a full screen page:
Window. Open ("Your. asp", "", "fullscreen = yes ")
*/
// -->
</SCRIPT>

4. shield the "minimize", "maximize", and "close" key in the upper right corner of the browser
<Script language = JavaScript>
Function window. onbeforeunload ()
{
If (event. clientx> document. Body. clientwidth & event. clienty <0 | event. altkey)
{
Window. event. returnvalue = "";
}
}
</SCRIPT>

Or open the page in full screen mode.
<Script language = "JavaScript">
<! --
Window. Open (www.32pic.com, "32pic", "fullscreen = 3, Height = 100, width = 400,
Top = 0, Left = 0, toolbar = No, menubar = No, scrollbars = No, resizable = No, location = No,
Status = No ");
-->
</SCRIPT>

Note: add the following content to the Body Tag:
Onbeforeunload = "javascript: Return false" // disable the window

5. shield the F5 key
<Script language = "JavaScript">
<! --
Function document. onkeydown ()
{
If (event. keycode = 116)
{
Event. keycode = 0;
Event. cancelbubble = true;
Return false;
}
}
-->
</SCRIPT>

6. Block the IE backend button
Use
<A href = "javascript: location. Replace (URL)">

7. Shielding the scroll bar of the Main Window
Add
Style = "overflow-Y: hidden"

8. shield the clipboard and clear the clipboard constantly.
Add
Onload = "setinterval ('clipboarddata. setdata (/'text/',/') ', 100 )"

9. Shielding website Printing
<Style>
@ Media Print {
* {Display: None}
}
</Style>

10. Disable the Save icon automatically displayed on ie6.0 Images
Method 1:
<Meta HTTP-EQUIV = "imagetoolbar" content = "no">

Method 2:

11. Shield all scripts on the page
<Noscrrept> </NoScript>

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.