Forum Moderators: open

Message Too Old, No Replies

document.write no longer works (migrated to xhtml MIME)

         

Asia_Expat

5:25 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



Here is my old javascript...

<script type="text/JavaScript" src="http://cache.example.com/abcdefg/spods.js?locale=en_US"></script>
<script type="text/JavaScript">
//<![CDATA[
for (var i = 0, n = wfSPODArray.length; i < n; i++) {
var spod = wfSPODArray[i];
spodHtml = '<a href=' + spod.link + ' target=_blank><img src=' + spod.photo.url + ' width=120' +' height=120 border=0' + '></a><br />' + '<a href=' + spod.link + ' target=_blank>' + spod.nickname + '</a>' + '<br />' + spod.quote + '<br />'
document.write(spodHtml);
}
//]]>
</script>

Can someone talk me through a different method of doing this, to make it work in an XHTML 1.1 document with .xhtml extension and MIME?

[edited by: Asia_Expat at 5:26 pm (utc) on Aug. 7, 2007]

DrDoc

6:50 pm on Aug 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<div id="foo"></div>

document.getElementById('foo').innerHTML = 'your string here';


Or, simply do not use XHTML as it is broken [webmasterworld.com]. Switch to HTML 4.01 is my firm recommendation.

Asia_Expat

7:16 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



Why?
I'm producing the correct application/xhtml+xml MIME type for my xhtml 1.1 documents and not the text/html MIME, so as far as I'm concerned, I'm 100 percent compliant in that regard.

I'll try out your javascript suggestion, thanks.

[edited by: Asia_Expat at 7:17 pm (utc) on Aug. 7, 2007]

Asia_Expat

7:19 pm on Aug 7, 2007 (gmt 0)

10+ Year Member



Actually, your suggestion has gone right over my head... I'm clueless. COuld you explain it to me so I can learn please?

londrum

8:39 pm on Aug 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



your code is no longer going to work. if you serve XHTML as application/xhtml+xml (which is the correct way of doing it) then document.write will fail.

there is no way around it - because it is a feature of XHTML. if you want to write something to the page then you have to do it the long-winded way - inserting all the nodes and elements separately.

sometimes it is too much hassle to do that, and it's easier to serve XHTML as text/html.