Michael Winter wrote:
On Wed, 21 Jan 2004 09:50:52 -0500, Brian Genisio
<Br**********@yahoo.com> wrote:
What is the most reliable way to grab the URL base for a document?
I can get window.location.protocol + window.location.host +
window.location.path... and that would work most the time, but if the
<BASE> tag is used, the URL base changes to that tag.
Is there a one-stop-shop location to retreive the URL base of the
document?
Try:
var baseAddr = null;
if( document.getElementsByTagName ) {
var elems = document.getElementsByTagName( 'base' );
if( elems.length ) {
baseAddr = elems[ 0 ].href;
}
}
If 'baseAddr' is null, try parsing the document URL.
Of course, you might not actually need the base address; it depends what
you're using it for.
Mike
What I need it for is tricky... I am writing my own DOM (not in JS), and
my application that uses the DOM needs to know the base URL for
retrieving links with relative paths. When I realized I didnt have it
anywhere in the DOM model, I thought that possibly I was missing
something. I wanted to be able to put in the same place the JS engine
would find it. But, if there is no direct method for retrieving it, I
have no issue.
I can create a method that is not exported to the JS engine for the
application.
Brian