views:

174

answers:

5

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 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.

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.

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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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>
+2  A: 

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.

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.

Gamecat
agree with question nonstandard usage - this should be done via classnames or IDs most likely
annakata
As I mentioned in my original post: The non-standard tags are part of the publishing system I use. They are placeholders which are transformed server-side into chunks of valid HTML code. Think of them as includes.
Fczbkk
The real question is, why Opera closes these tags at the end of the document (thus completely changing and invalidating the DOM tree) and ignores the closing slash? Behavior of other browsers in such situations seems more logical to me.
Fczbkk
A: 

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.

Ms2ger
You're right about it being interpreted as HTML, but <meta> has nothing to do with it (browsers never use <meta> to sniff content-type, only charset).
porneL
Of course you're correct—I believe I mentioned it because this made it pretty clear that the OP /wanted/ HTML (or, like most people do, just c-p'ed some code from the web).
Ms2ger
+1  A: 

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

Fczbkk
+2  A: 

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

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

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

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).

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

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.

porneL
A: 

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

singpolyma