admin管理员组文章数量:1406166
Here is my code:
$(document).keyup(function (e) {
alert("felt something!");
if (e.keyCode == 44) {
alert("felt PS");
ccd();
}
});
function ccd() {
if (clipboardData) {
window.clipboardData.setData('text', '');
}
}
In chrome, the ccd function does nothing (which is fine), but the message "Felt PS" pops up every time I hit the PS button. However, in IE (7-9), I can get one "Felt PS" message to appear. After that, hitting PS does nothing, but hitting any other key causes a "Felt something!".
Any one have any ideas what might be causing this issue?
Here is my code:
$(document).keyup(function (e) {
alert("felt something!");
if (e.keyCode == 44) {
alert("felt PS");
ccd();
}
});
function ccd() {
if (clipboardData) {
window.clipboardData.setData('text', '');
}
}
In chrome, the ccd function does nothing (which is fine), but the message "Felt PS" pops up every time I hit the PS button. However, in IE (7-9), I can get one "Felt PS" message to appear. After that, hitting PS does nothing, but hitting any other key causes a "Felt something!".
Any one have any ideas what might be causing this issue?
Share Improve this question asked Dec 5, 2012 at 21:26 PFranchisePFranchise 6,75211 gold badges59 silver badges73 bronze badges2 Answers
Reset to default 6I don't have enough Cool Points to make ments, but I do know this:
In Internet Explorer, print screen's KeyUp event will fire once--and only once--provided that another key is pressed first. By pressing another key again, print screen will be detected again: but once and only once.
This works across pages, so logging into a website and then navigating several pages, then hitting print screen: detected.
Having IE remember your login on your next visit, navigate the same several pages, hit print screen: not detected.
This is why Chase's updated answer about ALT + Print Screen is correct. By depressing alt first you have caused the keypress necessary for print screen to be detected...once.
Faked keyboard events created with Javascript are not sufficient to artificially induce this behavior, whatever it is that causes print screen to be detected (or not) lies within IE itself (as the same JS will work just fine in Firefox).
While not a full answer to your question, I hopefully can provide some insight based on my own experiences trying to solve this same problem.
For IE you need to be careful with e
, as older versions of IE use the global window.event
object. Try the following code instead:
$(document).keyup(function (e) {
if(!e) e = window.event; //check for e, otherwise use the global window.event
var keyCode = e.which || e.keyCode //changed as not all browsers use keyCode
alert("felt something!");
if (keyCode == 44) {
alert("felt PS");
ccd();
}
});
function ccd() {
if(window.clipboardData) { //changed to look for window.clipboardData instead otherwise throws an error in other browsers.
window.clipboardData.setData('text', '');
}
}
Please note the mented lines above where I've changed your code.
EXAMPLE
UPDATE:
Chances are you have to push ALT + PRINT SCREEN in order for the event to register for that key. I'm not 100% sure why at the moment, so if anyone else happens to know please edit the answer or leave it in the ments.
**Please note the revised code as well.
本文标签: javascriptIE only detecting first keyup for print screen key (others work every time)Stack Overflow
版权声明:本文标题:javascript - IE only detecting first keyup for print screen key (others work every time) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744369448a2602946.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论