如何让浏览器识别自定义的用户定义标签?
我正在尝试为浏览器(Firefox 或 IE 或 Chrome)开发插件/扩展。这样做的目的是插件/扩展应该识别我自己的自定义标签之一。
例如:
<myowntag1>
...
<mysubtag1 ... />
...
</myowntag1>
如何使用插件/扩展让浏览器识别这一点?
I am trying to develop a plugin/extension for a browser (Firefox or IE or Chrome). The purpose of this is that the plugin/extension should recognize one of my own-custom tags.
Eg:
<myowntag1>
...
<mysubtag1 ... />
...
</myowntag1>
How do I make a browser recognize this using a plugin/extension?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您的问题让我想起了线程 How XML 使用和解释? - 您的浏览器有没有用于未知标签的 api,但它有一个用于将 xml 转换为名为 XSLT 的其他任何内容(包括 html)的 API。我知道做你想做的事情的唯一方法是将你的网页编写为 XHTML(这是 XML,甚至可以使用 HTML5)。请注意,包含 XML 声明的第一行位于其位置,并添加包含对 XSLT 样式表的调用的第二行。编写此样式表 - 它必须复制 XML/XHTML 源页面中除您自定义的标签之外的所有内容。这些必须转换为所需的 HTML 输出。该解决方案适用于所有主要浏览器,尽管从一开始就使用转换后的 HTML 可能不太复杂。要打开新选项卡,您可以使用链接的“target”属性(Test)。这将根据您的浏览器首选项打开一个新选项卡或窗口。
Your Question reminds me on the thread How XML used and interpreted? - your browser has no api for unknown tags, but it has one for transformation of xml to anything else (including html) named XSLT. The only way I know to do what you want is to write your webpage as XHTML (which is XML and is possible even with HTML5). Be aware that the first line containing the XML Declaration is at its place and add a second line containing the call for a XSLT stylesheet. Write this stylesheet - it must copy everything from the XML/XHTML source page except your self defined tags. These must be transformed into the desired HTML output. This solution works with every major browser, though it may be less complicated to use the transformed HTML from start. To open a new tab you could use the "target" attribute of the link (<a href="http://test.com" target="newtab">Test</a>). This opens a new tab or window depending on your browser preferences.
能够在 XML 页面中嵌入任意 XML(在用户定义的命名空间中),并使命名空间以某种方式与理解此 XML 词汇的插件代码相关联,这是我们许多人共同的梦想。不幸的是,定义 HTML5 的组织 (WHATWG) 正在朝着相反的方向发展:他们并不认为这种可扩展性是一种要求,并且在 HTML 中嵌入 XML 变得越来越困难而不是更容易。唯一的例外是像 SVG 或 MathML 这样的 XML 词汇表,它们出于某种原因吸引了 WHATWG 上的人员并得到了他们的认可。
The idea of being able to embed arbitrary XML (in a user-defined namespace) within an XML page, and have the namespace somehow associated to plug-in code that understands this XML vocabulary, is a dream which many of us have shared. Unfortunately the group defining HTML5 (WHATWG) are moving in the opposite direction: they don't see this kind of extensibility as a requirement, and embedding XML in HTML is becoming harder rather than easier. The only exception is for an XML vocabulary like SVG or MathML that for some reason appeals to the folks on WHATWG and gets endorsed by them.
如果您从 JavaScript 手动解析标签,这似乎是一项可行的任务。例如,这就是 Facebook FBML 命名空间标签的实现方式。
假设我们有一个带有自定义标签
custom:header
的 html,它应该变成h1
:在内容脚本中我们可以这样做:(
我在这里使用 jQuery)。这会将我们的标签变成:
您还可以为自定义标签注入 css 文件:
Seems like a doable task if you parse tags manually from a javascript. This is how Facebook FBML namespace tags are implemented for example.
Lets say we have this html with custom tag
custom:header
that should turn intoh1
:In a content script we can do:
(I am using jQuery here). This will turn our tag into:
You can also inject a css file for your custom tags:
使用文档类型中引用的自定义 DTD,例如使用
mymymy.dtd
的示例:在将其上传到服务器之前了解其优缺点:
验证自定义 DTD
不要使用自定义 DTD< /p>
自定义 DTD 解释不正确
Use a custom DTD which is referenced in the doctype, such as the example using
mymymy.dtd
:Be aware of the pros and cons before uploading it to a server:
Validating a Custom DTD
Don't use a Custom DTD
Custom DTDs Interpreted Incorrectly