HTML5 支持替换上下文菜单吗?
我知道您可以添加上下文菜单项(目前仅在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,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.
支持这一点的不是 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.