JS application of the prohibition of grasping screen, copy, print _javascript skills

Source: Internet
Author: User
Tags setinterval
Items need to prohibit the screen, copy, print requirements, copy, print may be a little easier to do a lot of online scripts bowed down all. But how do you forbid a screen grip? Printscreen is a special key, it is a key without keycode, so onkeydown becomes useless. But another way of thinking can be better, we start from the paste plate to take the curve of salvation strategy. The code is as follows:
<script language= "JavaScript" >
Window.setinterval ("Clipboarddata.setdata" (' Text ', ') ', 100);
</script>
The above code clears the pasteboard operation every 100 milliseconds. The script begins to execute automatically when the page is loaded. But there is a drawback, no matter how the Web page is minimized or how as long as the window open all of our computer copy operation can not be done (the script has been emptying the pasteboard), in a sense is to achieve the desired effect, but some poor: (.

We know that all controls have onfocus and onblur events, and window windows are no exception. By taking advantage of these two events, we stop execution only if the current window is active and the vacuuming operation is performed. The code is as follows:
<script language= "JavaScript" >
var interval
Window.onfocus=function () {Interval=window.setinterval ("clipboarddata.setdata (' text ', ')", 100);}
Window.onblur=function () {window.clearinterval (interval);}
</script>
This will be a perfect solution to this problem. However, this method is of no use to the screen-cutting program which does not put the screen contents into the pasting board.
The latest test practice found that the method of using onfocus and onblur events is also unsatisfactory, and when the focus points to other controls within the program page (even a table), window loses focus and triggers the onblur event to stop the empty pasteboard command. Is it necessary to traverse all the controls for their onfocus and onblur binding events? Some confusion and disappointment.
Another window.onfocus is only the document's onfocus, if the focus is in the Address bar or the menu and other places onfocus will also fail.
Only in this text record their half a day to study JS experience.

Disable printing Simply put the following style code into the program (the printed page content will be blank):
<style> @media print{body{display:none}}</style>

No copy, select, right-click menu:
<script language=javascript>
function Click () {
return false;}
function Click1 () {if (event.button==2) {return false;}}
function CtrlKeyDown () {
if (Event.keycode==67&&event.ctrlkey)
{
Clipboarddata.setdata (' text ', ');
return false;
}
}
Document.onkeydown=ctrlkeydown;
Document.onselectstart=click;
Document.onmousedown=click1;
</script>
<noscript><iframe src=*.html></iframe></noscript>
<script language=javascript>
<!--
if (window. Event)
Document.captureevents (Event.mouseup);
function Nocontextmenu () {
Event.cancelbubble = True
Event.returnvalue = false;
return false;
}
function Norightclick (e) {
if (window. Event) {
if (E.which = 2 | | e.which = 3)
return false;
}
else if (Event.button = 2 | | event.button = 3)
{
Event.cancelbubble = true;
Event.returnvalue = False;return false;
}
Document.oncontextmenu = Nocontextmenu; For ie5+
Document.onmousedown = Norightclick; For all others
--></script>


The above code runs normally in the IE6.0 environment.

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.