Tag Archives: Browsers

HTML "name" attribute, Firefox misbehaves

It's been a long time since I wrote something about web-dev, that's because I code less web-stuff recently 🙂

"id" vs. "name" attributes

so far, I thought that "id" should be used for unique IDs, and "name" can be used for non-unique names, i.e. multiple HTML tags with the same name. I've been using document.getElementsByName(str) to get an array of elements with the same name.

Today I've figured out that it's only partially legal: the name attribute can be used only for specific elements (such as INPUT), but cannot be used on many elements (such as DIV). For some reason, Firefox accepts the name tag for any HTML element, while IE follows HTML 4.01 and doesn't accept name tags for "illegal" HTML tags.

Proof of concept

The next piece of JS/HTML code, gives different results on both browsers:

<div name="foo">bla</div>
<script type="text/javascript">
alert(document.getElementsByName("foo").length)
</script>

Results:

  • Firefox 3: 1
  • IE 7: 0

Here is a nice explanation with a full list of "name"-allowed HTML tags.

Cross-browser tab control keyboard shortcuts

The more keyboard shortcuts - the better. The amazing fact is that both Firefox and IE have very similar keyboard shortcuts for handling tabs:

Ctrl+T Create a new tab
Ctrl+W Close current tab
Ctrl+PgDn, Ctrl+PgUp
Ctrl+Tab, Ctrl+Shift+Tab
Go to next/previous tab
Ctrl+[0-9]
(In Linux: Alt+[0-9])
Go to tab #[0-9]

Got something else? 🙂