troubleshooting Question

document.write + application/xhtml+xml + mozilla

Avatar of dorward
dorward asked on
Web Languages and StandardsJavaScriptWeb Development Software
10 Comments1 Solution115723 ViewsLast Modified:
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).
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros