- From: Thomas Broyer <t.broyer@gmail.com>
- Date: Sat, 24 May 2008 19:45:06 +0200
- To: public-html@w3.org
On Sat, May 24, 2008 at 6:24 PM, Andrew Sidwell <w3c@andrewsidwell.co.uk> wrote: > > http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0A%3Ca%20href%3D%22%20%20%20http%3A%2F%2Fgoogle.com%2Fsearch%3Fq%3Dhello%20%20world%20%20%20%20%20%22%20class%3D%22%20%20%20raga%20taga%20%20%20%20%22%20new%3D%22%20%20%20raga%20%20haga%20%20%22%3Emeow%3C%2Fa%3E%0A > > <!DOCTYPE html> > <a href=" http://google.com/search?q=hello world " > class=" raga taga " new=" raga haga ">meow</a> > > I can't find anywhere in the spec which defines how to deal with whitespace > in attribute values. Special handling seems to be in browsers for the > "href" and "class" attributes, and more general handling in others. That's a bug in the Live DOM viewer (change the href attribute value to a relative URI reference to exhibit the bug: the DOM view shows the resolved URI). See for comparison (look at the "log" section): http://software.hixie.ch/utilities/js/live-dom-viewer/?%3C!DOCTYPE%20html%3E%0D%0A%3Ca%20href%3D%22%20%20%20search%3Fq%3Dhello%20%20world%20%20%20%20%20%22%20class%3D%22%20%20%20raga%20taga%20%20%20%20%22%20new%3D%22%20%20%20raga%20%20haga%20%20%22%3Emeow%3C%2Fa%3E%0D%0A%3Cscript%3E%0D%0Aw(%22href%3A%20%20%5B%22%20%2B%20document.getElementsByTagName('a')%5B0%5D.getAttribute('href'%2C%202)%20%2B%20%22%5D%22)%3B%0D%0Aw(%22class%3A%20%5B%22%20%2B%20(document.getElementsByTagName('a')%5B0%5D.getAttribute('class'%2C%202)%20%7C%7C%20document.getElementsByTagName('a')%5B0%5D.getAttribute('className'%2C%202))%20%2B%20%22%5D%22)%3B%0D%0Aw(%22new%3A%20%20%20%5B%22%20%2B%20document.getElementsByTagName('a')%5B0%5D.getAttribute('new'%2C%202)%20%2B%20%22%5D%22)%3B%0D%0A%3C%2Fscript%3E <!DOCTYPE html> <a href=" search?q=hello world " class=" raga taga " new=" raga haga ">meow</a> <script> w("href: [" + document.getElementsByTagName('a')[0].getAttribute('href', 2) + "]"); w("class: [" + (document.getElementsByTagName('a')[0].getAttribute('class', 2) || document.getElementsByTagName('a')[0].getAttribute('className', 2)) + "]"); w("new: [" + document.getElementsByTagName('a')[0].getAttribute('new', 2) + "]"); </script> > Opera and Safari3 trim any runs of whitespace in any attribute value into > just one space character. Ff3 does this but also then removes any leading > or trailing spaces from the class attribute. I don't have Opera at hand, but Safari 3 and Firefox 3 (RC1) don't change the attribute values; except Firefox 3 on the @class attribute (see the bug linked to by Boris). > IE removes all leading or trailing whitespace from the href attribute's > value, leaving other attribute values as written. Note that the script is using getAttribute(..., 2) to get the actual attribute value in IE: http://msdn.microsoft.com/en-us/library/ms536429(VS.85).aspx I've also defaulted to className is class is not found, as IE does not support getting attribute "class" (except in IE8, according to the doc http://msdn.microsoft.com/en-us/library/cc304686(VS.85).aspx ) IE7 then does not change the attribute values. -- Thomas Broyer
Received on Saturday, 24 May 2008 17:45:45 UTC