disable print screen key using javascript [duplica

2019-02-19 20:59发布

问题:

This question already has an answer here:

  • Stop User from using “Print Scrn” / “Printscreen” key of the Keyboard for any Web Page 11 answers

I'm trying to disable the print screen key on my website. This is what I have so far:

<SCRIPT type="text/javascript">
focusInput = function()
{
    document.focus();
};

processKeyEvent = function(eventType, event)
{
    if (window.event)
    {
        event = window.event;    
    }
    if(event.keyCode == 44) 
    {
        alert("Photos are copyright 2011");
        return(false);
    }
}
processKeyUp = function(event)
{
    processKeyEvent("onkeyup", event);
};

processKeyDown = function(event)
{
    processKeyEvent("onkeydown", event);
};

document.onkeyup = processKeyUp;
document.onkeydown = processKeyDown;

</SCRIPT>

But this isn't working. How can I disable the print screen key to prevent users from making a snapshot of my site?

回答1:

You can't. It's beyond your control, because print screen (unlike the in-browser print icon/Ctrl-P) is not a browser feature but a system feature.

Besides, any such attempt is futile and ultimately counter-productive. Because you will piss off the Joe Random User who wants to print the page because they want to read it on the bus or whatever and won't stop somebody who wants to abuse the images as they can always take advantage of the fact that the device is ultimately under their physical control and no software in the world can do anything against modification of the device (e.g. using a monitor with screen capture).