Link to home
Start Free TrialLog in
Avatar of dorward
dorward

asked on

document.write + application/xhtml+xml + mozilla

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).
Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

Could this be a bug? This seems to suggest it:
http://bugzilla.mozilla.org/show_bug.cgi?id=111514

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.
Avatar of dorward
dorward

ASKER

It could be a bug, but it doesn't stop me needing to deal with it. So it seems I'm looking for a work around. Any takers?
ASKER CERTIFIED SOLUTION
Avatar of ahosang
ahosang
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Any feedback? I could mess around further with a few things if you describe what's happening.
How's it going? Any good?
I'm not harassing because of any interest in points or whatever. It's just that I find questions like these very interesting(using DOM methods, Mozilla etc.), unlike the usual boring questions here! So, I'm really interested in progress as this was a learning experience for me too.
I can't replicate your exact situation, but I saved as .xhtml file(even works as .xml) and it seemed to work in Mozilla 1.1
Avatar of dorward

ASKER

That seems to work fine. Thank.
Glad to help. This made me think more about xhtml, xml etc.
hey David et all,

Thought you might be interested, I was reading some of the latest feeds in my RSS reader and came across this article, which linked to this particular question.  

http://www.xml.com/pub/a/2003/03/19/dive-into-xml.html


Just thought you might be interested to know!


bruno
I am trying to pass data from a javascript form and display the input in another webpage, such as thank you for you informantion and list that info on the thankYou.html page
hi korxt2,

this question is already closed and you will get no answers here, you need to ask your own question:  https://www.experts-exchange.com/Web/Web_Languages/JavaScript/askQuestion.jsp