I found it in the HTML5 specification :
First this , which discusses the .src property for the <script> :
The IDL attributes src, type, charset, defer, each should reflect the corresponding content attributes with the same name.
Then, if you follow the link in this specification to see what βreflectβ means, you can:
If the reflecting IDL attribute is a DOMString attribute, the contents of which the attribute is defined as containing the URL, and then, upon receipt of the IDL, the attribute must resolve the value of the content attribute relative to the element and return the received absolute URL if it was successful, or an empty string otherwise; and when setting up, you must set the content attribute to the specified literal value. If the content attribute is missing, the IDL attribute should return a default value if the content attribute has one or an empty string.
So, to describe this in a short short form: if you set the .src property (or any other property that accepts a URL), then exactly what you set is saved as a property. When you get the .src property, the return value is the final absolute URL after the property has been resolved relative to the base URL.
Regarding .getAttribute() , the specification for this is here . He just says:
Gets the attribute value by name.
Return value
DOMString | Attr value as a string or an empty string if this attribute does not have a specified or default value.
It is noteworthy that in this description there is nothing related to the special behavior that URL attributes have when reading their properties directly, as described above. Thus, the use of .getAttribute() does not have such a special "reflected" behavior. It simply returns the original attribute value without special getter behavior.
This is intentional behavior and has been this way for a long time. There are also specific developer sites for specific browsers that describe behavior.
Reading the .src property always returns the full URL, regardless of what you assigned in HTML or through Javascript.
Reading the same property with .getAttribute("src") returns exactly what was in the HTML.
Microsoft documents how IE behaves in this regard for any tag that has a URI as a property, starting with IE8 here .
Mozilla reports how Firefox behaves in this regard for images here .
Image demonstration (although all tag types that have the src or href property have the same behavior (including <script> tags):
var t = document.getElementById("target"); log("target.getAttribute('src') = ", target.getAttribute('src')); log("target.src = ", target.src);
<head> <script src="http://files.the-friend-family.com/log.js"></script> <base href="http://dummyimage.com"> </head> <img id="target" src="/200x100/000/fff">
In fact, here is a little utility that uses this fact:
function makeAbsolute(uri) { var a = document.createElement("a"); a.href = uri; return a.href; } var x = makeAbsolute("test.html"); document.write(x);