Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-27-2003, 02:03 PM   PM User | #1
ahosang
Regular Coder

 
Join Date: Sep 2002
Location: Surrey, UK
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
ahosang is an unknown quantity at this point
mozilla + document.write +xhtml

I participate on another forum and a user there has a problem. I'll reprint the problem exactly.
<problem>
I have a number of XHTML pages that I need to include some content in using JavaScript. (It has to be with JavaScript as it adds a style sheet that hides a menu, if users without JavaScript come to the page it is essential that the styles do not get applied).

My code:

if (document.getElementById) {
document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/js.css\" media=\"screen\" />")
}

This works fine in a document servered as text/html, but in order to take advantage of Mozilla's XML parser I serve XHTML pages as application/xhtml+xml (which they should be served as) if the browser claims it supports that content type.

Now - how do I get this to work with the browser rendering XHTML instead of tag soup?

I do not want a flash of unstyled content (and some of the pages have a lot of content in them so there will be such a flash if the script is called using onload).
</problem>

I don't mind anyone going there and helping the guy and getting the kudos themselves, but as you know it's against forum rules to advertise another forum. If anybody(Alex, jkd or anybody for that matter) wants to e-mail me for address, you're welcome. I can't suggest that he comes here because that's against site rules over there obviously.
He's a good chap and I'd like to help him. It makes me learn as well. Obviously I'll liase with him regarding comments made here, as it's not my dilemma and I don't know the full ins and outs of it.
If there is any problem with this, please moderators, e-mail me!
ahosang is offline   Reply With Quote
Old 01-27-2003, 03:58 PM   PM User | #2
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
See this bug

Essentially related - it deals with having the document object in a page served as application/xhtml+xml inherit from HTMLDocument, instead of XMLDocument. Inheriting from HTMLDocument also includes inheriting the document.write() method.
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 01-27-2003, 04:38 PM   PM User | #3
ahosang
Regular Coder

 
Join Date: Sep 2002
Location: Surrey, UK
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
ahosang is an unknown quantity at this point
Thanks jason that's interesting link. I'll pass this on and give credit. Maybe you have a website I can give him and say you're the author if you wish.
ahosang is offline   Reply With Quote
Old 01-27-2003, 05:07 PM   PM User | #4
jkd
Senior Coder

 
jkd's Avatar
 
Join Date: May 2002
Location: metro DC
Posts: 3,163
Thanks: 1
Thanked 18 Times in 18 Posts
jkd will become famous soon enough
Dude, nothing wrong about linking to other forums... I sometimes link to JavascriptCity, and often link to CodingForums on other sites.....
__________________
jasonkarldavis.com
jkd is offline   Reply With Quote
Old 01-27-2003, 05:20 PM   PM User | #5
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
I thought application/xml+xhtml was unuseable anyway, due to IE trying to download rather than display pages served with this mime type..?
brothercake is offline   Reply With Quote
Old 01-27-2003, 05:43 PM   PM User | #6
ahosang
Regular Coder

 
Join Date: Sep 2002
Location: Surrey, UK
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
ahosang is an unknown quantity at this point
>> Dude, nothing wrong about linking to other forums... I sometimes link to JavascriptCity, and often link to CodingForums on other sites.....
Ok, but I certainly can't provide any link to other forums there. They're quite strict on that!!
This is quite interesting bug link that jason gave. The question of how the mime-type should be handled made for some good discussion.
ahosang is offline   Reply With Quote
Old 01-28-2003, 12:28 AM   PM User | #7
ahosang
Regular Coder

 
Join Date: Sep 2002
Location: Surrey, UK
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
ahosang is an unknown quantity at this point
Possible solution

I offered this bit of code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script>
var l=document.createElementNS("http://www.w3.org/1999/xhtml","link");
l.setAttribute("rel", "stylesheet");
l.setAttribute("type", "text/css");
l.setAttribute("href", "/css/js.css");
l.setAttribute("media", "screen");
document.getElementsByTagName("head")[0].appendChild(l);

</script>
</head>

<body>
Test Page
</body>
</html>
ahosang is offline   Reply With Quote
Old 01-29-2003, 08:42 PM   PM User | #8
ahosang
Regular Coder

 
Join Date: Sep 2002
Location: Surrey, UK
Posts: 119
Thanks: 0
Thanked 0 Times in 0 Posts
ahosang is an unknown quantity at this point
The code I posted was accepted as the solution. Interesting stuff!
ahosang is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:13 PM.


Advertisement
Log in to turn off these ads.