为什么触发F11按键事件不起作用? [英] Why trigger F11 press event doesn't work?

查看:1029
本文介绍了为什么触发F11按键事件不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚看了这个问题:按下全屏页面按钮而不是F11

操作要求用其他热键替换 F11 ,所以我想知道我可以模拟按 F11 让事情有效。

我了解到我可以在JQuery中使用触发器来模拟按键事件,所以我做了类似这样的事情:

I just read this question: Full Screen Page by pressing button instead of F11
The op asked to replace F11 with other hot keys, so I'm wondering that maybe I can simulate press F11 to get things work.
I learned that I can use trigger in JQuery to simulate key press event, so I do something like this:

$("body").keyup(function (e) {
    alert(e.which);
});
var e = $.Event("keyup");
e.which = 122; // # Key code of F11
$("body").trigger(e);  

当我运行这个时,我得到警告说122,但似乎它没有给出希望的结果。那里有限制吗?

When I run this, I got the alert says 122, but it seems that it doesn't give the hoped result. Is there a restriction there?

我在这里做了一个小提琴: http:// jsfiddle.net/ap295/5/

I made a fiddle here: http://jsfiddle.net/ap295/5/

推荐答案

我认为这是一个:)来检测它.. 。

I think this is the one :) to detect it ...

$(document).keyup(function(e){
   if(e.which==122){
       e.preventDefault();//kill anything that browser may have assigned to it by default
       //do what ever you wish here :) 
       alert('F11 pressed');
       return false;
   }
});

但触发它(不可能

但你不会阻止浏览器全屏显示:) ...
Reson给出的是,让我说我已经完全屏蔽了它,并希望用它来切换它kbd> F11 但你阻止我,我将不得不重新启动PC,[计算机文盲]这会带来安全风险,因为你阻止用户做他期望做的事情,他们可能认为PC坏了或者什么:)所以......你在那里。

But you will not prevent the browser from full screen :) ... Reson given is that , lets say I have full screened it somehow, and wish to toggle out of it using F11 but u are preventing me, I would have to restart PC, [computer illiterates] which poses security risk as you are preventing a user from doing something he is expecting to do, and they may think PC is broken or something :) so ...there you are.

这篇关于为什么触发F11按键事件不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆