使用Jquery模拟键盘按键

发布于 2024-11-16 12:29:08 字数 251 浏览 1 评论 0原文

单击 div 时是否可以模拟按键? 类似这样的:

$("mydiv").click(function(){
 Presskey->F5
});

实际上我试图模拟的键是 F11,所以人们可以按 div 并且窗口将全屏显示。我搜索过这个,我知道如果没有用户“许可”,不可能使窗口全屏显示,但在这种情况下,他会在按下按键时按下 div。事实上并不是每个人都知道 F11(我知道我总是可以输入“按 F11 全屏”)。谢谢'

Is it possible to simulate a keypress when I click a div?
Something like:

$("mydiv").click(function(){
 Presskey->F5
});

Actually the key I'm trying to simulate is F11, so people could press the div and the window would fullscreen. I've searched this and I know it's not possible to make window fullscreen without the user "permission" but in this case he would press the div as he pressed the key. The fact is not everyone knows about F11 (I know I could always put "Press F11 for fullscreen"). Thanks'

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

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

发布评论

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

评论(3

寄离 2024-11-23 12:29:08

是的,您可以模拟按下 F11,但是您无法模拟它的作用,这是一个本机浏览器功能(因为它只在 JavaScript VM 中有效)区域),而不是由 JavaScript 触发的。

“按 F11 全屏”是您的最佳选择,如果您可以从 JavaScript 触发任何浏览器行为(例如 Ctrl+S 等),请考虑安全问题。

顺便说一句,即使在其他领域,例如,您可以在锚点上模拟点击事件,它将触发与之相关的所有 JavaScript 优点......但它不会实际遵循链接< /em>,浏览器中的一些(大多数)事情发生在JavaScript 级别,您无权访问任何内容。

Yes you can simulate F11 being pressed, but you can't simulate what that does, which is a native browser function (as it would only have an effect in the JavaScript VM area), and not one triggered by JavaScript.

"Press F11 for fullscreen" is your best option here, think of the security issues if you could trigger any browser behavior from JavaScript, e.g. Ctrl+S, etc.

As an aside, this is true even in other areas, for example you can simulate a click event on an anchor and it'll trigger all the JavaScript goodness hooked up to it...but it won't actually follow the link, some (most) things in a browser happen above the JavaScript level, where you don't have access to anything.

梦里的微风 2024-11-23 12:29:08

无法以编程方式强制执行全屏,也无法通过按键模拟无法通过 JavaScript 访问的操作。

如果您正在使用 HTML 视频,您可能需要查看 this支持跨浏览器。

You cannot programmatically enforce fullscreen, nor can you with keypresses simulate actions which aren't otherwise accessible through JavaScript.

If you are working with HTML video, you may want to have a look at this, which is not cross-browser supported.

楠木可依 2024-11-23 12:29:08

这存在一个安全问题,因为它可以被一些恶意脚本用来利用它作为一种迷惑用户的方法,让他们做一些他们不应该做的事情......或者强迫他们访问一个网站(请记住大多数网络用户并不那么聪明,其中 70% 都是愚蠢的)

There is a security issue with this as it can be used by some malicious scripts to exploit it as a method to confuse user and make them do some things that they are not supposed to do... or forcing them to one website ( remember that most of web users aren't that smart and 70% of them are just stupid)

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