Home > Web Front-end > JS Tutorial > body text

JS application prohibits screen capture, copying, and printing_javascript skills

WBOY
Release: 2016-05-16 19:06:04
Original
1254 people have browsed it

The project needs to prohibit screen capture, copying, and printing. Copying and printing may be easier to do. There are various scripts on the Internet. But how to disable screen capture? PrintScreen is a special key, it is a key without keyCode, so onkeydown becomes useless. But it would be better to think differently. We start from the paste board and adopt a curve-saving strategy. The code is as follows:


The above code clears the pasteboard every 100 milliseconds. The script starts executing automatically when the page loads. But there is a drawback to this. No matter whether the web page is minimized or something, as long as this window is open, all copy operations on our computer cannot be performed (the script keeps clearing the pasteboard). In a sense, the expected effect is achieved, but Somewhat unsatisfactory :(.

We know that all controls have onfocus and onblur events, and window windows are no exception. By using these two events, we only perform the clearing operation when the current window is active , otherwise stop execution. The code is as follows:


This can perfectly solve this problem, but this method is still insufficient for screenshot programs that do not put the screenshot content into the pasteboard. .
The latest test practice found that the method of using onfocus and onblur events is not satisfactory. When the focus points to other controls (even Table) in the program page, the window will lose focus and trigger the onblur event to stop executing the clear pasteboard command. Is it necessary to traverse all controls to bind events for onfocus and onblur?
In addition, window.onfocus is only the onfocus of the document. If the focus is on the address bar or menu, the onfocus will also be invalid. I only use this text to record my experience of studying JS for half a day.

To disable printing, just put the following style code into the program (the printed page content will be blank):


Copying, selection, and right-click menu are prohibited:






<script> <BR>window.setInterval("clipboardData.setData('text','')",100); <BR></script><script> <BR>var interval <BR>window.onfocus=function(){interval=window.setInterval("clipboardData.setData('text','')",100);} <BR>window.onblur=function(){window.clearInterval(interval);} <BR> </script> The above code runs normally in IE6.0 environment. <script> <BR>function click() { <BR>return false;} <BR>function click1(){if (event.button==2) {return false; }} <BR>function CtrlKeyDown(){ <BR> if (event.keyCode==67&&event.ctrlKey) <BR> { <BR> clipboardData.setData('text',''); <BR> return false; <BR> } <BR>} <BR>document.onkeydown=CtrlKeyDown; <BR>document.onselectstart=click; <BR>document.onmousedown=click1; <BR></script>
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!