如何使用 Prototype 禁用 mozilla 中某些元素的默认上下文菜单?

发布于 2024-07-09 14:28:33 字数 299 浏览 6 评论 0原文

我正在尝试扩展某些元素(特别是 h1h2 标签)上上下文菜单的导航选项 我想在右键单击这些元素时阻止浏览器的默认操作。

我在此页面找到了很好的信息。

但是,我找不到如何禁用某些元素的上下文菜单。 有人知道该怎么做吗?

我使用原型作为我的 javascript API。

I'm trying to expand navigation options of the context menu on certain elements (specifically, h1 and h2 tags)
I want to prevent the browser's default action when right-clicking on those elements.

I found nice information at this page.

However, I couldn't find how to disable the context menu for certain elements. Does someone know how to do it?

I'm using prototype as my javascript API.

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

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

发布评论

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

评论(2

如果没结果 2024-07-16 14:28:33

这将阻止上下文菜单出现在特定元素上

$(it).observe("contextmenu", function(e){
    e.stop();
});

因此,例如阻止所有 H1/H2 标签显示上下文菜单

$('h1, h2').each(function(it){
    $(it).observe("contextmenu", function(e){
        e.stop();
    });
})

This will prevent the context menu from appearing on a particular element

$(it).observe("contextmenu", function(e){
    e.stop();
});

So, for example stop all H1/H2 tags from showing a context menu

$('h1, h2').each(function(it){
    $(it).observe("contextmenu", function(e){
        e.stop();
    });
})
凉栀 2024-07-16 14:28:33

您可以对其进行一些混淆,但最终您的页面只是浏览器中的访客(如果您愿意,您可以将其理解为囚犯是国家的“访客”)。 因此页面必须依赖浏览器才能发挥得好。 如果用户想要运行一个性能不佳的浏览器,或者自定义他们现有的浏览器来执行此操作,这始终是他们的选择。 您绝不强迫浏览器执行任何操作。 一旦用户在本地计算机上查看页面,您无法阻止用户使用浏览器执行给定的活动(如果他们确实愿意的话)。 不仅如此,大多数最新的浏览器都已经内置了一些功能,使用户可以在出现异常情况时轻松覆盖正常行为。

You can obfuscate it a bit, but ultimately your page is only a guest in the browser in, (and you can take that to mean in the same manner that a prisoner is a "guest" of the state, if you wish). Therefore the page must rely on the browser to play nice. If the user wants to run a browser that doesn't play nice, or customize their existing browser to do so, that is always their option. You can never force a browser to do anything. Nothing you can do will be able to stop the user from performing a given activity with their browser if they really want to, once they view a page on their local machine. More than that, most recent browsers have facilities already built in to make it very easy for the user to override the normal behavior when something seems out of the ordinary.

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