473,394 Members | 1,866 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,394 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 23921
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>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.