HTML5 中的自定义标签命名空间实现
对于我正在构建的音频播放器,我希望有一个类似于 Google 和 Facebook 用于其共享小部件的标签。例如,它可能是:
<fp:player data-type="mp3" data-href="/path/to/file.mp3" />
实现此自定义标记的最佳方法是什么,并使其在尽可能多的浏览器中有效?
For an audio player I'm building, I'd like to have a tag similar to what Google and Facebook use for their share widgets. For example, it could be:
<fp:player data-type="mp3" data-href="/path/to/file.mp3" />
What's the best way to implement this custom tag, and have it be valid in as many browsers as possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
上述链接的规范还指出,
如果我正确理解了规范,昆汀发布的报价是指用户代理扩展。 (我认为它们指的是特殊的浏览器和浏览器插件。)用户代理不应创建新的标签或属性。 Web 开发人员可以使用他们喜欢的任何虚构标签和属性。该规范明确指示用户代理开发人员考虑未知的标签和属性,并将它们包含在 DOM 中以及渲染页面时。
使用脚本访问它们是有点棘手的地方。 IE 7 和 8 允许您添加命名空间来查找这些自定义标记,这会使您的文档在技术上无效 - 但仍然完全正常工作!
请参阅此处(我的博客): http://blog.svidgen.com/2012/10/building-custom-xhtml5-tags.html
The above-linked specification also states,
Quentin's posted quote, if I understand the specification correctly, is referring to user-agent extensions. (By which I assume they mean both special browsers and browser plugins.) User-agents should not create new tags or attributes. Web developer can use whatever made-up tags and attributes they like. And the specification explicitly instructs user-agent developers to account for unknown tags and attributes, and include them in the DOM and when rendering the page.
Accessing them with script is where it becomes a little tricky. IE's 7 and 8 for you to add a namespace to find those custom tags, which makes your document technically invalid -- but still fully functional!
See here (my blog): http://blog.svidgen.com/2012/10/building-custom-xhtml5-tags.html
来自HTML 规范:
因此您无法创建它并符合规范,Facebook 和 Google 非常非常顽皮。
您似乎正在尝试重新发明
无论如何,
元素 。因此,只要使用它,扩展语言的问题就消失了。From the HTML specification:
So you can't create it and conform to the specification and Facebook and Google are very, very naughty.
You appear to be trying to reinvent the
<audio>
element anyway. So just use that and the problem of extending the langage goes away.观察 html5shim 或 html5shiv 如何创建新元素:https://github。 com/aFarkas/html5shiv/blob/master/src/html5shiv.js
本质上你只需要 document.createElement() 元素,然后你就可以使用它。
observe how the html5shim or the html5shiv create new elements: https://github.com/aFarkas/html5shiv/blob/master/src/html5shiv.js
essentially you just have to document.createElement() the element, then you can use it.