The Artima Developer Community
Sponsored Link

Web Buzz Forum
Javascript, the DOM and application/xhtml

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic    
Flat View: This topic has 0 replies on 1 page
Simon Willison

Posts: 282
Nickname: simonw
Registered: Jun, 2003

Simon Willison is a web technology enthusiast studying for a Computer Science degree at Bath Uni, UK
Javascript, the DOM and application/xhtml Posted: Jul 2, 2003 1:51 AM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Simon Willison.
Original Post: Javascript, the DOM and application/xhtml
Feed Title: Simon Willison: Web Standards
Feed URL: http://feeds.simonwillison.net/swn-everything
Feed Description: Simon Willison's Web Standards cateory
Latest Web Buzz Posts
Latest Web Buzz Posts by Simon Willison
Latest Posts From Simon Willison: Web Standards

Advertisement

One of the side-effects of switching my blog to serving pages as application/xhtml+xml to browsers that support it (mainly Gecko engine browsers) was that my blockquote citations script simply stopped working in those browsers. The reason this happened is touched upon by Mark Pilgrim in The Road to XHTML 2.0: MIME Types: essentially, when dealing with XML documents Gecko needs you to use document.createElementNS in place of document.createElement when manipulating the DOM.

I fixed this by replacing all occurrences of document.createElement(elementName) with document.createElementNS('http://www.w3.org/1999/xhtml', elementName), thinking this would be an end to the problem. Unfortunately, this broke the script in IE 6, a problem which I didn't notice for several weeks as I very rarely use that browser.

I began to receieve repeated reports of a scripting error in IE, so the other day I finally got round to looking in to it and realised it was failing on the call to document.createElementNS. Once I'd figured that out, the solution to the problem was a little bit of object detection:

function createElement(element) {
  if (typeof document.createElementNS != 'undefined') {
    return document.createElementNS('http://www.w3.org/1999/xhtml', element);
  }
  if (typeof document.createElement != 'undefined') {
    return document.createElement(element);
  }
  return false;
}

By replacing my calls to document.createElementNS with a call to my new createElement function, I finally got the script working in both browsers. It should work in other modern DOM supporting browsers as well.

Read: Javascript, the DOM and application/xhtml

Topic: Mini-Tabs get a makeover Previous Topic    

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use