The first thing to note is that window.frames
is just an alias for window
:
The window, frames, and self IDL attributes must all return the Window object's browsing context's WindowProxy object.
The relevant part of the specification is here:
The supported property names at any moment consist of the following, in tree order, ignoring later duplicates:
- the browsing context name of any child browsing context of the active document whose name is not the empty string,
- the value of the name content attribute for all a, applet, area, embed, form, frameset, img, and object elements in the active document that have a non-empty name content attribute, and
- the value of the id content attribute of any HTML element in the active document with a non-empty id content attribute.
So it doesn't matter which one is "preferred".
If the id and name of an element are the same, then one will be used to determine the name and the other will be ignored. If id="a"
is used and name="a"
is ignored, you get a
. If it was the other way around, you would still get a
.
If the id and name of an element are different, then they can both be used to reference it.
If two different elements share a value between their name and id attributes, then whichever element comes first will take that name. Which particular attribute is used doesn't matter.
Use of id and name attributes directly like that is not recommended. They can clash with existing properties of the window object. It is better to use getElementById
or querySelector
so you can explicitly say you are looking for an element in the DOM.