ATLief
ATLief

Reputation: 437

Is it standard web-browser behaviour to prepend the current URL to incomplete links?

If a website includes an incomplete link such as the following:

<a href="#my_div">Link</a>
<a href="?my_var=1">Link</a>

Is it standard, universal behaviour that the link would be interpreted as the current URL with the href value appended to it?

Upvotes: 1

Views: 109

Answers (1)

zzzzBov
zzzzBov

Reputation: 179266

The HTML5 spec defines how [href] attributes behave

The href attribute on a and area elements must have a value that is a valid URL potentially surrounded by spaces.

which links to:

A string is a valid URL potentially surrounded by spaces if, after stripping leading and trailing whitespace from it, it is a valid URL.

which links to:

A URL is a valid URL if it conforms to the authoring conformance requirements in the URL standard. [URL]

which links to a sizable block of text, but I think the following is important:

Most of the URL-related terms used in the HTML specification (URL, absolute URL, relative URL, relative schemes, scheme component, scheme data, username, password, host, port, path, query, fragment, percent encode, get the base, and UTF-8 percent encode) can be straightforwardly mapped to the terminology of [RFC3986] [RFC3987].


As for the "incomplete link" examples you included in your question. They are examples of a "fragment" and "query" respectively, which have an implicit relative URL of . which represents the current URL (note that it will not merge query strings or document fragment identifiers).

Upvotes: 2

Related Questions