-
Notifications
You must be signed in to change notification settings - Fork 22.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HTMLBaseElement.href docs #31464
Conversation
Preview URLs (comment last updated: 2024-07-12 00:52:24) |
Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com>
|
||
{{APIRef("HTML DOM")}} | ||
|
||
The **`href`** property of the {{domxref("HTMLBaseElement")}} interface contains a string that is the URL to use as the base for relative URLs, like links pointing to a fragment in the document (`<a href="#example">`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like "like" here, because it tends to be an ambiguous word. "such as" would be better. But I'm not sure whether we need this clause at all. Better would be to make "relative links" link to a proper explanation: https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/Creating_hyperlinks#absolute_versus_relative_urls might do, although I wonder if this would be a suitable glossary topic, or if we could extend https://developer.mozilla.org/en-US/docs/Glossary/URL to cover it.
```js | ||
const base = document.getElementsByTag("base")[0]; | ||
console.log(base.href); // 'https://developer.mozilla.org/example' | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also show the result if there is no href
attribute?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there can only be one base element in a page, so we can't include two in a single example; opting to not include and target
-only <base>
example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could have two examples. I'd have done that, except that this violates CSP and I get an error for that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I think is OK without both. The expected behaviour is stated.
Co-authored-by: wbamberg <will@bootbonnet.ca>
Co-authored-by: wbamberg <will@bootbonnet.ca>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
edits per review
```js | ||
const base = document.getElementsByTag("base")[0]; | ||
console.log(base.href); // 'https://developer.mozilla.org/example' | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there can only be one base element in a page, so we can't include two in a single example; opting to not include and target
-only <base>
example.
@wbamberg when you have a chance, a re-review would be great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the example into a live example. Merging as this is now IMO sufficient (and Will is on holiday).
* Add HTMLBaseElement.href docs * Update files/en-us/web/api/htmlbaseelement/href/index.md Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com> * Update files/en-us/web/api/htmlbaseelement/href/index.md * Update files/en-us/web/api/htmlbaseelement/href/index.md Co-authored-by: wbamberg <will@bootbonnet.ca> * Update files/en-us/web/api/htmlbaseelement/href/index.md Co-authored-by: wbamberg <will@bootbonnet.ca> * Apply suggestions from code review * Apply suggestions from code review * Make example into live example * Update files/en-us/web/api/htmlbaseelement/href/index.md --------- Co-authored-by: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com> Co-authored-by: Estelle Weyl <estelle@weyl.org> Co-authored-by: Estelle Weyl <estelle@openwebdocs.org> Co-authored-by: wbamberg <will@bootbonnet.ca> Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
This adds the missing
HTMLBaseElement.href
page.Part of the project to document all interoperable features (mdn/discussions#476)