为什么触发F11按下事件不起作用?

发布于 2024-11-16 06:45:20 字数 595 浏览 4 评论 0原文

我刚刚读过这个问题: 全屏页面按按钮而不是F11
操作员要求将 F11 替换为其他热键,所以我想知道也许我可以模拟按 F11 来让事情正常工作。
我了解到我可以在 JQuery 中使用触发器来模拟按键事件,所以我做了这样的事情:

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

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

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

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);  

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深巷少女 2024-11-23 06:45:20

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

$(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;
   }
});

但触发它(不可能

但你不会阻止浏览器全屏:)......
给出的原因是,假设我已经以某种方式全屏了它,并希望使用 F11 切换它,但你阻止了我,我必须重新启动 PC,[计算机文盲] 这会带来安全问题风险是因为你阻止用户做他期望做的事情,他们可能会认为电脑坏了或者什么:)所以......你就在这里。

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;
   }
});

but triggering it (NOT POSSIBLE)

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.

三寸金莲 2024-11-23 06:45:20

你不能这样做。该问题中的链接答案提供了一种在 jQuery 事件框架内使用 jQuery 模拟按键的方法。

您根本无法触发或伪造按键。所以这个问题的答案是:

不,这是不可能的

You can not do this. The linked answer in that question provides a way with jQuery to simulate key-presses, within the jQuery event framework.

You simply can not trigger or fake keypresses. So the answer of this question is:

No, this is impossible

扶醉桌前 2024-11-23 06:45:20

您将无法从网页内覆盖浏览器的内置热键。

也许能够在浏览器扩展中做到这一点,但是仅仅更改应用程序的热键肯定是严重的矫枉过正。

无论如何,您为什么要覆盖标准键盘快捷键?我不明白。它们已经成为标准很长时间了;大多数用户都会熟悉它们,并且如果将它们更改为其他内容,会发现很奇怪。

You won't be able to override the browser's built-in hotkeys from within a web page.

You might be able to do it in a browser extension, but that's would surely be serious overkill just to change the application's hotkeys.

In any case, why would you even want to override the standard keyboard shortcuts? I don't get that. They've been standard for a long time; most users will be familiar with them, and will find it very odd if they've been changed to something else.

旧人 2024-11-23 06:45:20

不要把它看成“我如何触发F11?”的问题。 - 看看“如何触发或模拟全屏?”

使用旧版本的 IE,您可以直接全屏打开一个新窗口:

window.open(someURLorOther, '', 'fullscreen=yes, scrollbars=auto');

或者您可以使用 window.open 打开特定大小的新窗口。

或者您可以尝试调整当前窗口的大小以填满屏幕:

moveTo(0,0);
resizeTo(screen.availWidth,screen.availHeight);

但是仅仅因为您可以并不意味着您应该您应该< em>从不调整当前窗口的大小——这几乎让每个人都烦恼。打开一个新窗口到您选择的大小是更合理的,尽管如果它太大它可能会很烦人,并且在正常的网页上(其中“正常”我可能意味着不是某种基于浏览器的数据输入应用程序)最好不要打开新窗口。

Don't look at is as a question of "How do I trigger F11?" - look at is as "How do I trigger or simulate full-screen?"

With older versions of IE you can open a new window straight into full-screen:

window.open(someURLorOther, '', 'fullscreen=yes, scrollbars=auto');

Or you can use window.open to open a new window of a specific size.

Or you can try to resize the current window to fill the screen:

moveTo(0,0);
resizeTo(screen.availWidth,screen.availHeight);

However just because you can doesn't mean you should. You should never resize the current window - this annoys practically everyone. Opening a new window to a size you choose is more reasonable, though if it's too big it can be annoying, and on a normal web page (where by "normal" I probably mean not some kind of browser-based data-entry app) it is nicer not to open new windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文