保持网页中上下文菜单的原生样式

发布于 2024-09-09 04:11:40 字数 244 浏览 2 评论 0原文

我知道每个人都讨厌他们的上下文菜单被弄乱,所以我所要求的是相反的。我尝试过寻找能够更改网页中上下文菜单的 JavaScript 插件,但我发现它们非常具有侵入性。 (即上下文菜单现在仅包含开发人员选择的项目)。有没有一种方法可以简单地将项目添加到上下文菜单,同时保留用户的正常项目并同时保留菜单的本机样式?我发现的相同插件要求开发人员为菜单定义新样式。我不认为重新发明轮子有什么意义。

我问这个问题是因为我的一个客户希望在用户右键单击时向网站添加额外的功能。

I know everyone hates when their context menus get messed with so what I'm asking for is the opposite of that. I've tried looking for javascript plugins that deal with changing the context menus in webpages, but I find that they are very intrusive. (i.e. the context menu now only contains the items that the developer chooses). Is there a way to simply add an item to the context menu, all while keeping the user's normal items and at the same time keeping the native style of the menu? The same plugins I have found require the developer to define a new style for the menus. I don't see the point in reinventing the wheel.

I ask because a client of mine wants to add extra functionality to the site when the user right clicks.

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

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

发布评论

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

评论(1

佞臣 2024-09-16 04:11:40
  • 上下文菜单无法通过普通的 javascript + DOM 进行修改。它(通常)可以被一些看起来和行为都像上下文菜单的动态 HTML 所抑制和取代。这就是为什么样式看起来不同,以及为什么你不能组合内置和自定义上下文菜单...用 javascript 完成的“上下文菜单”根本不是真正的上下文菜单。

  • 如果事件被取消,上下文菜单可能会被禁用,但这取决于浏览器——大多数浏览器都提供了一个选项来禁止隐藏上下文菜单;如果启用的话,即使事件被取消,菜单也会显示。这会导致显示两个“上下文菜单”,真正的上下文菜单和伪造的 javascript 一个。

  • 要根据用户的系统外观设置网页样式,请使用 CSS2 中定义的系统颜色 ( http://www.iangraham.org/books/xhtml1/appd/update-23feb2000.html ) 和/或 CSS3 外观属性 ( http://www.w3.org/TR/2004/CR-css3-ui-20040511/# system )

编辑:响应“我的一个客户希望在用户右键单击时向网站添加额外的功能” - 您可能想要建议客户只有当网站是一个网络应用程序(例如谷歌文档)时,他们才应该这样做,用户会合理地期望上下文菜单做一些不寻常的事情。您还应该确保有一种非隐藏的方式来完成可以通过上下文菜单完成的所有操作。

  • The context menu can't be modified via normal javascript + DOM. It (usually) can be suppressed and replaced by some dynamic HTML that looks and acts like a context menu. This is why the styling appears different, and why you can't combine built-in and custom context menus... 'context menus' done in javascript are not really context menus at all.

  • The context menu may be disabled if the event is cancelled, but that's up to the browser -- most browsers provide an option to disallow hiding the context menu; if that's enabled then even if the event is cancelled the menu will show. This results in two "context menus" displaying, the real context menu and the faked-up javascript one.

  • To style web pages based on the user's system appearance, use the system colors defined in CSS2 ( http://www.iangraham.org/books/xhtml1/appd/update-23feb2000.html ) and/or the CSS3 appearance property ( http://www.w3.org/TR/2004/CR-css3-ui-20040511/#system )

Edit: In response to "a client of mine wants to add extra functionality to the site when the user right clicks" -- you might want to advise the client that they should only do this if the site is a web application (for example like google docs) where users would reasonably expect the context menu to do something out of the ordinary. You should also make sure that there is a non-hidden way to do everything that can be done via the context menu.

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