0

Here's my code

$(document).on("keyup", function(e) {
    console.log(e.key);
    if (e.key == "PrintScreen") {
        e.preventDefault();
        clearClipBoard();
    }
})

function clearClipBoard() {
    if (navigator.clipboard) { // Chrome or Edge
        navigator.clipboard.writeText(""); 
    }
    else if (window.clipboardData) { // Internet Explorer
        window.clipboardData.setData("Text", "");
    }
}

When the page loaded first time, or blur and focus back again, the keyup event of PrintScreen cannot be detected. But if I press other key first and then press the Prt Scn key, it can be detected successfully.

It only happens when using IE, when I using Chrome or Edge, it doesn't have this problem.

I've tried to trigger a keyup event of other key when the page focus back, but the Prt Scn key still cannot be detected.

$(window).on("focus", function() {
    $.alert("focus");
    let e = $.Event('keyup');
    e.key = 'a'; 
    $("body").trigger(e);
})

I found someome has the same question but no answer. IE 11 Print screen issue

Any one have any ideas what might be causing this issue?

33nya
  • 51
  • 2
  • Have you tested this behavior in other browsers (other than IE)? I only ask because I didn't know users of targeted web apps would in any case, be using Internet Explorer. It's simply a dead software other than grandmas not knowing how to install a different browser or users unwilling to buy a different (non-XP) computer to support the hardware. ... Besides all that, by "targeted" do you even want IE users to access your application? – mardubbles Apr 12 '22 at 04:08
  • @mardubbles It's okay when using other browsers like Chrome or Edge(I added it to the post). The customer wants this application run on IE, so I try to find a way to solve this problem. Thank you for the reply ;) – 33nya Apr 12 '22 at 05:50
  • If the customer wants to run your app in IE, then you can ask Why? – mardubbles Apr 12 '22 at 06:14
  • I can reproduce the issue. It seems to be an issue with IE and simulate keypress before pressing PrintScreen still can't fix the issue. As IE desktop app is going to retire soon, the issue won't be fixed in IE. If you must use IE, I think what you want can't be achieved in IE. – Yu Zhou Apr 13 '22 at 04:20

0 Answers0