473,221 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

Get the URL base

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?

Thanks,
Brian

Jul 20 '05 #1
2 23914
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

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #2
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

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

52
by: Dick Moores | last post by:
I need to figure out how to compute pi to base 12, to as many digits as possible. I found this reference, <http://mathworld.wolfram.com/Base.html>, but I really don't understand it well enough....
2
by: Stephan Br?nnimann | last post by:
Dear all thanks to Scott Meyers (ME C++, item 33) we know assignment operators should be protected in the base class. Is there a common pattern (similar to virtual construction via `clone()')...
6
by: Paul | last post by:
In real life situation, do we ever come across a situation where we would need two base objects in an object. A snippet is worth 1000 words (: so... class Base { }; class Derived1:public Base...
7
by: Jef Driesen | last post by:
Suppose I have an abstract base class that looks like this: template <typename T> class base { public: // Typedefs typedef double value_type; typedef std::size_t size_type; public: //...
7
by: Baski | last post by:
Base class: class AssetBase { string _clli; public string CLLI { get
5
by: Andy | last post by:
Hi all, I have a site with the following architecture: Common.Web.dll - Contains a CommonPageBase class which inherits System.Web.UI.Page myadd.dll - Contains PageBase which inherits...
1
by: miben | last post by:
I want to create a new inherited class givin its base. For example: class Base { public: void operator =(const Base &base) { // copy base items } }; class Inherits: public Base {
6
by: Taran | last post by:
Hi All, I tried something with the C++ I know and some things just seem strange. consider: #include <iostream> using namespace std;
0
by: robert | last post by:
Hi all, I'm having a hard time resolving a namespace issue in my wsdl. Here's an element that explains my question, with the full wsdl below: <definitions name="MaragatoService"...
11
by: jyck91 | last post by:
// Base Conversion // Aim: This program is to convert an inputted number // from base M into base N. Display the converted // number in base N. #include <stdio.h> #include <stdlib.h>...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.