HTML5 支持替换上下文菜单吗?

发布于 2024-12-10 01:23:40 字数 234 浏览 0 评论 0原文

我知道您可以添加上下文菜单项(目前仅在 Firefox 中),但是您可以用指定的项目完全替换上下文菜单吗?

我的意思是,如果我使用以下内容创建上下文菜单:

  • 操作 1
  • 操作 2

然后,当打开上下文菜单时,会显示这些项目。

我还指的是根据 HTML5 menu 元素规范而不是当前的实现。

I know that you can add context menu items(currently only in Firefox) but can you replace the context menu entirely with items specified?

By that I mean that if I create a context menu with:

  • Action 1
  • Action 2

Then when opening the context menu ONLY those items would appear.

I also mean according to the HTML5 menu element specification and not current implementations.

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

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

发布评论

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

评论(2

沧桑㈠ 2024-12-17 01:23:40

不,HTML5 没有,您也不能。让菜单元素影响上下文菜单的一个重要原因是允许作者能够在上下文菜单上进行操作,而不会破坏浏览器中内置的对用户很重要的所有功能。因此,允许网页作者删除现有的上下文菜单选项将违背这一点。

No, HTML5 doesn't and you can't. An important reason for having the menu element affect the context menu was to allow authors to be able to put operations on the context menu without disrupting all the facilities that are built into the browser and are important to the user. So allowing the web page author to remove the existing context menu options would defeat the point.

琉璃繁缕 2024-12-17 01:23:40

支持这一点的不是 HTML,而是浏览器。

有些浏览器确实允许您禁用上下文菜单并通过右键单击激活其他内容,但其他浏览器则不允许。

多年来,大多数浏览器都可以实现这一点(当然早在 HTML5 之前),但一两个浏览器从未允许这样做,因为您会干扰标准浏览器 UI。 (Opera 总是很奇怪)

对于支持它的浏览器,您需要使用 onmousedown 事件,该事件将为您提供一个事件对象,该对象将告诉您按下了哪个鼠标按钮。

或者您可以使用 jQuery 插件——似乎有一些插件可以用于此目的。尝试这个这个

It isn't HTML that supports this, but the browser.

Some browsers do indeed allow you to disable the context menu and activate something else on right click, but others don't.

It's been possible in most browsers for ages (certainly long before HTML5), but one or two browsers have never allowed it, on the grounds that you're interfering with the standard browser UI. (Opera was always the odd one out here)

For browsers that do support it, you need to use the onmousedown event, which will give you an event object that will tell you which mouse button was pressed.

Or you can use a jQuery plugin -- there seem to be a few of them around for this. Try this one or this one.

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