Javascript web page full screen and prohibit special buttons to prevent page refresh and forward and backward (domestic version)

Source: Internet
Author: User

Javascript web page full screen and prohibit all webpage buttons (domestic version)

Yang Yong, bjash@126.com

The following code is sourced from network collection. Here, we only modify and integrate some errors,

This code is suitable for making pages that require full screen and disabling special buttons! Normal input and multiple choice are not affected.

// Save this file as forbidden. js. When used: <script language = "JavaScript" src = "forbidden. js"> </SCRIPT>

// Disable Content Selection
Function document. onselectstart () {return false ;}
// Prohibit drag and drop of content
Function document. ondragstart () {return false ;}
// Disable context menu
Function document. oncontextmenu () {return false ;}
// Disable printing. Add the code in the style:
// @ Media Print {body {display: None}. In this way, the printed webpage is empty.

Function isfocus (eltid)
{// Determine whether an element gets the focus
// Alert (event. currenttarget. ID );
// Alert (document. activeelement. tagname );
If (document. activeelement. ID = eltid)
{// Alert ('get focal point ');
Return true;
}
Else {
// Alert ('unobtained focal point ');
Return false;
}
}//
Function isFullscreen ()
{If (window. screenLeft = 0 & amp; empty rows Doc ument. body. clientWidth = window. screen. width
&&#;Doc ument. body. offsetHeight = window. screen. height)
{// Location. href = "Help Page, set the IE parameter! ";
// Alert ('fullscreen ');
Return true;
}
Else
{// Alert ('non-fullscreen ');
Return false;
}
}

Function auto_submit ()
{
// Alert ('login ');
}
Window. onblur = auto_submit;
// The following Code enables full screen display
Function window. onload ()
{
// Hide the scroll bar
// Document. getelementsbytagname ('body') [0]. style. Overflow = 'sidd ';
// Document. getelementsbytagname ('body') [0]. Scroll = "no ";
Isfullscreen ();//***************
}
 
Function document. oncontextmenu () {event. returnvalue = false;} // right-click the screen
Function window. onhelp () {return false;} // block F1 help
 
// Mask some buttons
Function document. onkeydown ()
{
// Type of the object when the document. activeElement. type key is pressed: type Value
// Typeof (document. activeElement. type) = 'undefined') when you focus on the body, the type is undefined. Be sure to use typeof to judge !!!
// The name BODY, INPUT, and TEXTAREA of the document. activeElement. tagName label. The INPUT cannot distinguish between text and radio.

// Unblocking the back page: the Key activation object is blocked when a single button or multiple button or BODY is selected, while text and textarea are not blocked.
If (event. keyCode = 8 & (document. activeElement. type = 'Radio '|
Document. activeElement. type = 'check' | typeof (document. activeElement. type) = 'undefined '))

{Event. keyCode = 0; event. returnValue = false ;}
Else if (event. ctrlKey & event. keyCode = 82) {event. keyCode = 0; event. returnValue = false;} // shield Ctrl + R

Else if (event. keyCode = 116 | event. keyCode = 122) {event. keyCode = 0; event. cancelBubble = true; event. returnValue = false;} // block F5, F11, and prevent event bubbles

Else if (event. ctrlKey & event. keyCode = 78) event. returnValue = false; // block Ctrl + n
Else if (event. ctrlKey & event. keyCode = 67) event. returnValue = false; // block Ctrl + v

Else if (event. shiftKey & event. keyCode = 121) event. returnValue = false; // block shift + F10

Else 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

Else if (window. event. altkey) & (window. event. keycode = 115) // mask Alt + F4
{Window. showmodelessdialog ("about: blank", "", "dialogwidth: 1px; dialogheight: 1px"); Return false ;}

Else if (window. event. altkey) & (window. event. keycode = 37) | (window. event. keycode = 39 )))

{// Block Alt + direction keys, → forward or backward webpage, but hold down the Alt key, it cannot be blocked
Event. returnvalue = false;
}
}

Related Article

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.