Opera中的非标准标记行为

时间:2022-10-18 10:19:40

I'm working with a publishing system that uses custom tags. These are interpreted on the server. The problem is, that they cause big problems with Opera, when viewed locally (custom tags are not interpreted).

我正在使用使用自定义标签的发布系统。这些在服务器上解释。问题是,当在本地查看时,它们会导致Opera出现大问题(不会解释自定义标记)。

Opera is handling these tags differently from other browser. It looks like it is closing the tag at the end of the document (even if the tag contains closing slash). I'm just wondering, if such behavior is considered bug or feature.

Opera以不同于其他浏览器的方式处理这些标签。看起来它正在关闭文档末尾的标记(即使标记包含结束斜杠)。我只是想知道,如果这种行为被认为是错误或功能。

Also, if you have any idea how to hack such code so that I can debug HTML+CSS for Opera locally (without interpreted custom tags), please let me know. Thank you.

此外,如果你有任何想法如何破解这样的代码,以便我可以在本地调试Opera + HTML + CSS(没有解释自定义标签),请告诉我。谢谢。

Try the folowing code to see it in action (live example):

尝试下面的代码来看它的实际效果(实例):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Non-standard tag behavior in Opera</title>

    <style type="text/css" media="all">
        div { background: yellow; padding: 1em; }
        nonstandardtag { border: 1px solid red; }
    </style>

</head>

<body>

<div>
    <nonstandardtag>content of non-standard tag</nonstandardtag>
    main tag content
</div>

<div>
    <nonstandardtag />
    main tag content
</div>

</body>

</html>

5 个解决方案

#1


I use opera for more than 5 years. It is the browser that approaches the standard the best. Most of the sites that look bad in Opera are "optimized" for IE.

我使用歌剧超过5年。浏览器最接近标准。大多数在Opera中看起来很糟糕的网站都是针对IE进行“优化”的。

But an obvious question is, why do you need to use nonstandard tags? You can use the div and span tags for almost any nonstandard solution.

但一个显而易见的问题是,为什么需要使用非标准标签?您可以将div和span标签用于几乎所有非标准解决方案。

#2


Short: it's not a bug. Despite the DOCTYPE, your page is not interpreted as XHTML (and this is intentional).

简而言之:这不是一个错误。尽管有DOCTYPE,但您的页面不会被解释为XHTML(这是故意的)。

HTML simply doesn't support the self-closing tag syntax the same way as XML.

HTML只是不像XML一样支持自动关闭标记语法。

In HTML, in practice <foo /> is the same as <foo> or <foo /="">. In theory it's same as <foo></foo>&gt;.

在HTML中,实际上 相同。从理论上讲,它与 >相同。

You need to tell browser to interpret page as X[HT]ML. DOCTYPE is not enough. To do this locally, file has to have .xml or .xhtml extension. When you serve file over HTTP, you must set Content-Type header to application/xhtml+xml or similar XML type (for static files usually .xhtml file extension does the job).

您需要告诉浏览器将页面解释为X [HT] ML。 DOCTYPE是不够的。要在本地执行此操作,文件必须具有.xml或.xhtml扩展名。当您通过HTTP提供文件时,必须将Content-Type标头设置为application / xhtml + xml或类似的XML类型(对于静态文件,通常.xhtml文件扩展名完成此任务)。

Your live example is served as text/html, so it won't be interpreted as XHTML, and won't work as you expect.

您的实例作为text / html提供,因此不会被解释为XHTML,并且无法按预期工作。

BTW: XHTML doesn't allow non-standard elements. If you want to add your own elements anyway, you should at least use your own namespace.

顺便说一句:XHTML不允许使用非标准元素。如果你想要添加自己的元素,至少应该使用自己的命名空间。

#3


This seems to be fixed in Opera 10. So I guess it was not a feature.

这似乎是在Opera 10中修复的。所以我猜这不是一个功能。

#4


One, you don't need non-standard elements. Two, whatever you claim with your doctype, this isn't XHTML but HTML (as you make clear with the <meta http-equiv="Content-Type" content="text/html. That obviously means that browsers use their HTML parsers, and those don't (and shouldn't) support XML's shorthand syntax <element/> for empty elements.

一,您不需要非标准元素。第二,无论你使用doctype声明什么,这不是XHTML而是HTML(正如你用

#5


Short answer: there are no guarentees or requirements on what a User Agent may do if you feed it malformed data.

简短回答:如果您提供错误数据,用户代理可能不会做任何保证或要求。

#1


I use opera for more than 5 years. It is the browser that approaches the standard the best. Most of the sites that look bad in Opera are "optimized" for IE.

我使用歌剧超过5年。浏览器最接近标准。大多数在Opera中看起来很糟糕的网站都是针对IE进行“优化”的。

But an obvious question is, why do you need to use nonstandard tags? You can use the div and span tags for almost any nonstandard solution.

但一个显而易见的问题是,为什么需要使用非标准标签?您可以将div和span标签用于几乎所有非标准解决方案。

#2


Short: it's not a bug. Despite the DOCTYPE, your page is not interpreted as XHTML (and this is intentional).

简而言之:这不是一个错误。尽管有DOCTYPE,但您的页面不会被解释为XHTML(这是故意的)。

HTML simply doesn't support the self-closing tag syntax the same way as XML.

HTML只是不像XML一样支持自动关闭标记语法。

In HTML, in practice <foo /> is the same as <foo> or <foo /="">. In theory it's same as <foo></foo>&gt;.

在HTML中,实际上 相同。从理论上讲,它与 >相同。

You need to tell browser to interpret page as X[HT]ML. DOCTYPE is not enough. To do this locally, file has to have .xml or .xhtml extension. When you serve file over HTTP, you must set Content-Type header to application/xhtml+xml or similar XML type (for static files usually .xhtml file extension does the job).

您需要告诉浏览器将页面解释为X [HT] ML。 DOCTYPE是不够的。要在本地执行此操作,文件必须具有.xml或.xhtml扩展名。当您通过HTTP提供文件时,必须将Content-Type标头设置为application / xhtml + xml或类似的XML类型(对于静态文件,通常.xhtml文件扩展名完成此任务)。

Your live example is served as text/html, so it won't be interpreted as XHTML, and won't work as you expect.

您的实例作为text / html提供,因此不会被解释为XHTML,并且无法按预期工作。

BTW: XHTML doesn't allow non-standard elements. If you want to add your own elements anyway, you should at least use your own namespace.

顺便说一句:XHTML不允许使用非标准元素。如果你想要添加自己的元素,至少应该使用自己的命名空间。

#3


This seems to be fixed in Opera 10. So I guess it was not a feature.

这似乎是在Opera 10中修复的。所以我猜这不是一个功能。

#4


One, you don't need non-standard elements. Two, whatever you claim with your doctype, this isn't XHTML but HTML (as you make clear with the <meta http-equiv="Content-Type" content="text/html. That obviously means that browsers use their HTML parsers, and those don't (and shouldn't) support XML's shorthand syntax <element/> for empty elements.

一,您不需要非标准元素。第二,无论你使用doctype声明什么,这不是XHTML而是HTML(正如你用

#5


Short answer: there are no guarentees or requirements on what a User Agent may do if you feed it malformed data.

简短回答:如果您提供错误数据,用户代理可能不会做任何保证或要求。