Closed
Bug 42066
Opened 24 years ago
Closed 24 years ago
Need to get absolute URI for .href HTMLLinkElement
Categories
(Core :: DOM: Core & HTML, defect, P2)
Core
DOM: Core & HTML
Tracking
()
RESOLVED
FIXED
M18
People
(Reporter: tim, Assigned: jst)
References
Details
(Whiteboard: [HAVE FIX])
Attachments
(2 files)
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
patch
|
Details | Diff | Splinter Review |
Many attributes in HTML are URIs, but accessing them through
element.getAttribute(...) does not return an absolute URI if the URI is
relative. The only way to resolve the URL from JavaScript is to access the
XPCOM interface "nsIURL", and pass in a base URI to resolve from.
Unfortunately getting the base URI is not easy through JavaScript; according to
the HTML specification, base URIs can be specified in the HTML BASE element,
through HTTP headers (which I don't think are acccessible through JavaScript),
and otherwise from the current document location.
Several HTML elements have already implemented convenience properties to
automatically resolve the URI. The <A> anchor element returns an absolute URI
through "anchorel.href" and the <IMG> element returns an absolute URI
through "imageel.src".
Getting an unresolved URI seems quite useless in most situations. Bug 2800
(<LINK> href) and Bug 1996 (<IMG> longDesc) both require a reliable method of
getting absolute URIs. This isn't really part of DOM compliance (I don't think
the DOM says anything about absolute URIs), but an implementation specific
issue.
Assignee | ||
Comment 2•24 years ago
|
||
I don't think we should change what getAttribute returns but I do think that
there should be a way to convert relative URL's to absolute URL's in the DOM (or
maybe not in the DOM, but in a way that's accessible from JS). I think DOM Level
3 will offer something like this for XML and XLinks and hopefully that can be
used in non-XML spcific cases too.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee | ||
Comment 3•24 years ago
|
||
This bug has been marked "future" because the original netscape engineer
workingon this is over-burdened. If you feel this is an error, that you or
another known resource will be working on this bug,or if it blocks your work in
some way -- please attach your concern to the bug for reconsideration.
Target Milestone: --- → Future
I agree, getAttribute should still return the URLs unmodified. And if there's
going to be a general way to do this with DOM Level 3 that would be great. In
the meantime, is it possible to get the above patch for the LINK tag checked
in? It basically copies existing code from nsHTMLAnchorElement.cpp to
nsHTMLLinkElement.cpp, so that "linkel.href" returns an absolute URL just
like "anchorel.href" does already.
Assignee | ||
Comment 5•24 years ago
|
||
Probably, but I'd prefer to simplify the patch a bit, the caching of the
canonical URL is IMO overkill here, the reason it was added in
nsHTMLAnchorElement is that it's needed there for performace reasons since the
style system uses that method a lot. I don't think we'd need the caching in
nsHTMLLinkElement so if you'd remove the caching and we'd be able to get
approval for this I (or you?) could check in the fix.
Can the patch to get the absolute URI for the LINK element href get checked
in? It's almost the same as the patch checked in for Bug 44115 for the
HTMLAreaElement.
Assignee | ||
Comment 8•24 years ago
|
||
Pulling this back and nominating for beta3, the patch is almost identical to
what was already done for anchors and area elements (for beta2) and should just be
checked in for both consistency with other elements and for backward
compatibility.
Status: NEW → ASSIGNED
Keywords: nsbeta3
Priority: P3 → P2
Summary: Need to get absolute URI for URI attributes of HTML elements → Need to get absolute URI for .href HTMLLinkElement
Whiteboard: [HAVE FIX]
Target Milestone: Future → M18
Looks like a patch just checked in for Bug 25963 takes care of this for
HTMLLinkElement. But there are still a number of URI attributes that do not
have this (i.e. img longdesc).
Assignee | ||
Updated•24 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Assignee | ||
Comment 10•24 years ago
|
||
Updated•24 years ago
|
Component: DOM Level 2 → DOM Style
Comment 11•24 years ago
|
||
Taking QA Contact on all open or unverified DOM Style bugs...
QA Contact: vidur → ian
Comment 12•24 years ago
|
||
Can someone explain how 'anchorel.href', 'imageel.src', and 'linkel.href' are
accessed. I wouldn't ask this here except that I can find this referenced
nowhere esle on the web or in bugzilla except for this bug.
I tried these two examples to see what happened:
<a href="somepage.html" onclick="alert(this.getAttribute('href')); return
false;">relative URI</a>
<a href="somepage.html" onclick="alert(this.getAttribute('anchorel.href'));
return false;">absolute URI</a>
I expect the first to give me "somepage.html"...and it does.
I expect the second to give me "http://[whereveriam.com/]somepage.html"...but
it doesn't.
It gives me a zero length string. Am I missing soemthing? At first glance,
I'd expect it to be looking for an attribute specifically named 'anchorel.href'
which, obviously, dosn't exist...but I can't figure out any other way
that 'anchorel.href' is meant to be used in the getElement() method?
Can anyone help out with this?
Jake
Assignee | ||
Comment 13•23 years ago
|
||
hoju, try:
<a href="somepage.html" onclick="alert(this.getAttribute('href')); return
false;">relative URI</a>
<a href="somepage.html" onclick="alert(this.href);
return false;">absolute URI</a>
Updated•23 years ago
|
Component: DOM Style → DOM HTML
QA Contact: ian → desale
Updated•22 years ago
|
QA Contact: desale → stummala
Component: DOM: HTML → DOM: Core & HTML
QA Contact: stummala → general
You need to log in
before you can comment on or make changes to this bug.
Description
•