HTML5的contextmenu属性 [英] HTML5 contextmenu attribute

查看:89
本文介绍了HTML5的contextmenu属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照教程创建一个 HTML5 contextmenu ,并且到目前为止我的网站上已经有了以下代码行:

 < a id =logohref =http://mywebsite.comcontextmenu =download-logo> 
< img class =default-logoalt =我的网站src =http://mywebsite.com/logox2-standard.png/>
< img class =retina-logoalt =我的网站src =http://mywebsite.com/logox2-retina.png/>

< menu type =contextid =download-logo>
< menu label =寻找我们的标志?>
< / menu>
< / menu>
< / a>

在Mozilla Firefox浏览器中浏览网站时,这非常合适,它是目前唯一支持它的浏览器:



HTML contextmenu属性(W3Schools)



然而,有一个polyfill可以在其他网页浏览器中增加额外的支持:

jQuery-contextMenu(GitHub)

一旦我将JavaScript文件包含到我的网站的< head> 标记中,我将这个polyfill应用于上面的当前代码中?



请记住我对JavaScript不太熟悉。



谢谢。

解决方案菜单和 menuitem HTML5候选推荐标准,但已被删除。 Firefox不应该再处理这些元素,其他浏览器都可以忽略它们。



事实上,整个上下文菜单部分出现在 20121217草稿已被删除。在特定的草稿中,它们与其他已删除的元素(如 hgroup 命令)标记为:


以下功能存在风险,可能因缺少实施而被删除。


所以简而言之:你不应该使用它,因为它不再被用在规范中。您应该找到替代方法来实现您正在尝试做的事情。


I'm following a tutorial to create a HTML5 contextmenu, and have so far got the following lines of code in my website:

<a id="logo" href="http://mywebsite.com"  contextmenu="download-logo">                  
    <img class="default-logo" alt="My Website" src="http://mywebsite.com/logox2-standard.png" />
    <img class="retina-logo" alt="My Website" src="http://mywebsite.com/logox2-retina.png" /> 

    <menu type="context" id="download-logo">
        <menu label="Looking For Our Logo?">
            <menuitem label="Download High Resolution (45KB)" icon="http://www.mywebsite.com/logo-icon.jpg" onClick="window.location.href='http://www.mywebsite.com/logo-retina.zip'"></menuitem>
            <menuitem label="Download Low Resolution (20KB)" icon="http://www.mywebsite.com/logo-icon.jpg" onClick="window.location.href='http://www.mywebsite.com/logo-standard.zip'"></menuitem>
        </menu>     
    </menu>
</a>

This works perfectly fine when viewing the website in Mozilla Firefox, which is currently the only browser that supports it:

HTML contextmenu Attribute (W3Schools).

However, there is a polyfill available that will add additional support in other web browsers:

jQuery-contextMenu (GitHub).

How do I apply this polyfill to my current code above, once I've included the JavaScript file in to the <head> tag of my website?

Please keep in mind I'm not very familiar with JavaScript.

Thank you.

解决方案

The menu and menuitem elements were featured in the initial HTML5 Candidate Recommendation but have since been removed. Firefox should not be handling these elements any more and other browsers are correct to ignore them.

In fact, the entire context menus section which was present in the 20121217 draft has been removed. Within that particular draft they're marked alongside other removed elements such as hgroup and command as:

The following features are at risk and may be removed due to lack of implementation.

So in short: you shouldn't use this at all as it's no longer featured in the specification. You should instead find alternative methods to achieve what you are trying to do.

这篇关于HTML5的contextmenu属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆