custom attributes in firefox

M

mrsd2c

I am building custom attributes as a means to pass data from the client
to the server. To accomplish this task, a class of "postback" is
applied to a link or button. When the link or button is clicked,
custom attributes are parsed from the link and submitted to the
application as hidden form fields. The code below better illustrates
the HTML:

<a class="postback" c:myAttribute1="value"
c:myAttribute2="value">submit</a>

This works fine in IE (6 and 7), however the JavaScript engine in
FireFox treats attributes as case-insensitive and, as a result, submits
the hidden input as "myattribute1" and "myattribute2". The server code
is case-sensitive, so it does not get the proper value. I was
wondering if there were any ways to mitigate this problem on the
client. I understand that there are many server-side solutions.
Additionally, I understand that the w3c recommends that attributes
should be case-sensitive. However, I have a need to make this work.
 
V

VK

This works fine in IE (6 and 7), however the JavaScript engine in
FireFox treats attributes as case-insensitive and, as a result, submits
the hidden input as "myattribute1" and "myattribute2".

HTML is case-insensitive, so are its tag names and attribute names (but
not attribute values). In this respect <a FOO="bar">, <a Foo="bar"> or
<a foo="bar"> is all the same for all browsers. But for the internal
representation (say for DOM Inspector display) UA "normalize" attribute
names by bringing them to one case. IE "normalize" to upper case, FF
"normalize" to lower case, and someone maybe normalize it to
camel-case, I donno :)
DOM methods hasAttribute, getAttribute, setAttribute in IE have
additional argument to switch the "normalization" off/on, but you check
on mozilla.org if they have this extension (possibly not).
The server code
is case-sensitive, so it does not get the proper value.

As you cannot predict the "normalization" results for UA, do
normalization yourselve cerver-side before process data (say everything
to upper case). That seems as the easiest solution. I presume you don't
have any burning necessity to have different attributes differing by
their case only like Foo and FOO ;-)
 
M

Martin Honnen

The code below better illustrates
the HTML:

<a class="postback" c:myAttribute1="value"
c:myAttribute2="value">submit</a>

Does that validate as HTML 4? Or as XHTML 1?
This works fine in IE (6 and 7), however the JavaScript engine in
FireFox treats attributes as case-insensitive and, as a result, submits
the hidden input as "myattribute1" and "myattribute2".

The JavaScript engine? That implements stuff like numbers, boolean,
strings, Date but does not implement any host objects like HTML element
objects.
What JavaScript code are you using exactly, to at least give us a chance
to try to understand what you do?

Additionally, I understand that the w3c recommends that attributes
should be case-sensitive. However, I have a need to make this work.

Well you could serve XML to Firefox, then I am sure it follows the rules
of XML and case-sensitivity:
<http://home.arcor.de/martin.honnen/javascript/2006/09/test2006091901.xhtml>
Despite your beliefs of what the JavaScript engine does.

If you let stuff parse by an HTML/SGML parser then expect some case
folding or case normalization to be done, for instance the SGML parser
the W3C validator uses normalizes attribute names to all upper case, see
the parse tree in
<http://validator.w3.org/check?uri=h...+automatically)&doctype=Inline&sp=1&verbose=1>

And what does it help if you adapt your code for (some version of)
Firefox? Another browser might do something different with its tag soup
parser. Custom attributes in HTML are not really reliable, and if you
even want case-sensitivity then you have choosen the wrong approach for
that validation feature you want.
 
M

mrsd2c

Thanks. I am serving HTML 4.01. I do not think it validates. Martin,
I learned a lot from your examples.

The following would be a good representation:

function listAttributes (element) {
for (var i = 0, l = element.attributes.length; i < l; i++) {
alert('name=' + element.attributes.name);
}
}

I am resigned to the fact that Firefox will normalize these attributes
per this doctype.

For what browsers would you not expect custom attributes to work?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top