homepage Welcome to WebmasterWorld Guest from 54.211.7.174
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Browsers / Opera Browser Usage and Support
Forum Library, Charter, Moderator: open

Opera Browser Usage and Support Forum

    
Opera @import fails with type application/xhtml+xml
Is it me, is it a bug, or is it by design?
mrobinson




msg:1585547
 2:13 pm on Aug 26, 2004 (gmt 0)

Sorry if this is the wrong forum for this post. A browser query, with XHTML, CSS and a little PHP but this seemed to be the right place.

I cannot get Opera 7.51 to @import stylesheets when the document has a content-type of application/xhtml+xml.

Here's the code that's involved (I've omitted most tags in the post to save space)

<!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" dir="ltr" xml:lang="en" lang="en">

<head>
<link rel="stylesheet" type="text/css" title="Standard" href="http://XXX/themes/default/style.css" />
<style type="text/css">
/*<![CDATA[*/
@import "http://XXX/themes/default/structure.css";
@import "http://XXX/themes/default/advanced.css";
/*]]>*/
</style>
</head>

I use this technique to deliver extra stylesheets to more modern browsers.
Everything works great. Pretty much every graphical browser loads the linked stylesheet, and only the more modern browsers read the imported style sheets (i.e. not NN4).

When I set the content-type to text/html everything works fine. If on the other hand I set it to application/xhtml+xml, Opera 7.51 ignores the @import statements (and so only the linked stylesheets load). I haven't tried other versions of Opera yet, but everything is fine in Firefox.

I'm checking $_SERVER["HTTP_ACCEPT"] and if the browser indicates that it will accept xhtml I set the following

@header("Content-Type: application/xhtml+xml; charset=ISO-8859-1");
@header("Vary: Accept");

Can I not rely on importing stylesheets with a document set as application/xhtml+xml or am I misunderstanding something?
Should I serve every page as text/html? (I hate myself for saying this - but at least it works).

Should I be using a different method of delivering stylesheets?
I could use a single stylesheet and resort to css hacks but I want to avoid that.

If anyone could duplicate this I'd be grateful to hear about it - I think I'm going mad.

Also, this is my first post on Webmaster World (hello everyone) so be kind. ;)

Thanks,
Mark

 

encyclo




msg:1585548
 2:28 pm on Aug 26, 2004 (gmt 0)

Welcome to WebmasterWorld [webmasterworld.com], mrobinson!

I haven't had a chance to test this fully, but have you tried removing the CDATA comments from around the @import statements? A quick test showed me that an uncommented @import on an XHTML document served as application/xhtml+xml worked fine in Opera 7.50.

mrobinson




msg:1585549
 2:45 pm on Aug 26, 2004 (gmt 0)

Hi encyclo,

Thanks for the welcome and for a prompt response.

I've made the changes you suggested and everything is working as it should. The only bug to report is me!

It didn't even occur to me that the CDATA part could be the problem. I stripped out just about everything to get to the bottom of this (yet I trusted the CDATA) lol.

I know that embedding javascript in XHTML needs CDATA, and I can't remember why I do this with style. I'm guessing that using CDATA here is wrong and I'll avoid it in future.

Are the good old <!-- comment --> tags best used to hide the style contents from legacy browsers?

Thanks again,
Mark

encyclo




msg:1585550
 3:26 pm on Aug 26, 2004 (gmt 0)

You could try adding the comments like this:

<style type="text/css"><!--/*--><![CDATA[/*><!--*/ 
...
/*]]>*/--></style>

Which is fairly crazy, but you might have better luck (I haven't tested it in Opera). You could also use a link element as for your first stylesheet, and in that linked stylesheet you place the two @import statements to call the two advanced stylesheets.

If you use standard HTML comments only when serving XHTML as application/xhtml+xml, then the user agent is supposed to silently remove the contents - so your stylesheets won't load. Using an uncommented style block risks displaying the contents on-screen, but only for very old browsers (read Netscape 2).

mrobinson




msg:1585551
 4:37 pm on Aug 26, 2004 (gmt 0)

Hi encyclo,

Your suggestion of linking to a stylesheet and then importing from there is an elegant solution and I can't believe it didn't occur to me before (hindsight is wonderful).

I'm looking forward to serving more application/xhtml+xml in the future.

Regards,
Mark

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Browsers / Opera Browser Usage and Support
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved