Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

The move to XHTML

Status
Not open for further replies.

tycaine

Programmer
Feb 8, 2003
29
CA
Ok, I'm taking the plunge, I've started moving from HTML 4.01 to XHTML 1.0 but am having just a few problems.

If I serve the pages as Content-Type text/html I have no problems whatsoever, I have validated pages, and everything displays great in both FireFox and IE 6... (At this point though the pages are little more than more organized HTML 4.01...)

Now, I know there's a problem with doing true XHTML on IE 6, so I set about 'sniffing' what the browser was sending to the server as far as what it could handle, and then set the Content-Type depending on whether the browser can only handle text/html (like IE 6) or true application/xhtml+xml (like FireFox).

Everything SEEMS to go well, until I realized that you cannot use document.write() in true XHTML/XML, which gives me my problem.

I understand that true XHTML/XML isn't fully supported yet (certainly not by Microsoft!) but I'm sure it is only a matter of time, and detecting the browser's abilities on the fly allows me to at least start in the right direction. BUT, if a number of things on my site use the document.write() ability right now, what do I have to do to make it work in true XHTML/XML??

Any help, and certainly any examples, would be welcomed as to how I go about setting up my pages so that I can deliver in both text/html (for IE) and application/xhtml+xml (for FF) depending on what is being used...

Help???


Ty
 
That isn't an IE problem vs. FF issue, nor is it a problem with application-type. The "document.write()" method simply isn't part of XHTML, that's all.

You need to research how to get/set node/element values, instead.

Thomas D. Greer
 
Thanks for both responses, and with my research since I posted the original message I understand it's not and IE vs FF issue, though I have to thank you for confirming it...

My main issue is trying to work out what the alternative to document.write() is, without making my head spin!!! :)

What IS the alternative to document.write()??

The information I've found is confusing to say the least, as to what to use to replace document.write()...

Can someone give me a for-instance?

In one instant I'm using the d.w() to write an email address (in an effort to make it harder for the email address to get spammed by sites scraping the page) so what would the alternative be?


Ty
 
In general, serve a "template" of the page. That is, a page with all of the underlying structural elements in place.

Then, to set the content of a particular element, "get" that element. One way you can do this is to give every element a unique ID. Then, use the "document.getElementById()" method, and use the ".innerHTML" property to set its content.

That's a first stab, however, and even that can be problematic with very strict XHTML. The canonical way is to use "document.createElementNS" to create any elements you wish, and then the ".setAttribute" method to create the attribute-value pairs, and then insert it into the page's DOM with ".appendName".

An example that's been floating around a lot is:

Old way to insert a linked stylesheet:

Code:
document.write("<link rel=\"stylesheet\" 
type=\"text/css\" href=\"/css/js.css\" media=\"screen\" />")

XHTML:

Code:
  var l=document.createElementNS("[URL unfurl="true"]http://www.w3.org/1999/xhtml","link");[/URL]
  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);

Thomas D. Greer
 
Thanks for the replies, and the links!

It looks like that's the way to go, but that's going to take a lot more work converting what I have to true DOM to get it into true XHTML.... (though, IE doesn't yet support true XHTML (as in served as xhtml+xml, as opposed to text/html), does anyone know whether version 7 of IE will?)

That's going to take a while so I think for now I'll set everything back to HTML 4.01, and go from there... At least until I have more time to get up to my elbows in DOM!!

Anyway, thanks again!!
 
If you have server-side capabilities (ASP, PHP, etc.), you might look for a script that changes everything from XHTML to HTML or HTML to XHTML depending on whether the application/xhtml+xml media-type is recognized by the browser.

An alternative is to use application/xml rather than application/xhtml+xml. I think IE recognizes application/xml, so that might work. It would be served as XML though, which could make IE show its XML document tree view. Here is a quick reference of media-types that can/cannot be used in certain documents: [URL unfurl="true"]http://www.w3.org/TR/xhtml-media-types/#summary[/url]
The W3C recommends application/xhtml+xml highly but states that application/xml is acceptable (for browser compatibility at the time).

I hope this helps.
 
does anyone know whether version 7 of IE will?
I do - it won't. See .

Actually that's kinda a good thing - they don't have the time to develop proper XHTML support for version 7, so they're being honest and not supporting the MIME type. It would have been easy for them to have treated application/xhtml+xml like text/html, but it would also have been wrong, as it would probably have put the mockers on them ever supporting it properly.

Let's just hope version 8 isn't another 5 years in coming...

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top