Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

document.write + application/xhtml+xml + mozilla

Posted on 2003-01-27
10
Medium Priority
?
111,102 Views
Last Modified: 2013-12-16
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).
0
Comment
Question by:dorward
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 12

Expert Comment

by:ahosang
ID: 7822285
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.
0
 
LVL 17

Author Comment

by:dorward
ID: 7824038
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?
0
 
LVL 12

Accepted Solution

by:
ahosang earned 1400 total points
ID: 7825855
darn, reading throught the bug thread more carefully, I was hoping to find a easy workaround. It seems to be either a bug, or uncertain implementation issue, but as you say, you have to DEAL with it.
So, you cannot serve as text/html because you need XML parsing, but you do not have document.write() available in XML document because it doesn't have that HTMLDocument method. The workaround may be to use XML methods - createElementNS specifically. I take it you already have xhtml namespace declared in <html>(as below) etc.

<!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>
if (document.getElementById) {
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>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 12

Expert Comment

by:ahosang
ID: 7830790
Any feedback? I could mess around further with a few things if you describe what's happening.
0
 
LVL 12

Expert Comment

by:ahosang
ID: 7837767
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
0
 
LVL 17

Author Comment

by:dorward
ID: 7839937
That seems to work fine. Thank.
0
 
LVL 12

Expert Comment

by:ahosang
ID: 7840691
Glad to help. This made me think more about xhtml, xml etc.
0
 
LVL 18

Expert Comment

by:bruno
ID: 11700676
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
0
 

Expert Comment

by:k0rxt2
ID: 14250447
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
0
 
LVL 18

Expert Comment

by:bruno
ID: 14256242
hi korxt2,

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question