How to retrieve the homepage filename when filename doesn't exist in URL

D

Diarmaid

Hi!

I've built a dynamic navigation system which compares the filename in
the document URL with the filename in the navigation link in order to
determine which link to highlight as "active".

The problem I have is that the URL returned by document.URL (and
location.href) does not include the filename when I'm sitting on the
homepage. This means that when I compare the nav link with the
document URL, I don't get a match.

Eg:
document.URL and location.href returns "http://mydomain.com/"
The navigation link is "http://mydomain.com/index.html"

How can I find out the current document's filename if I'm sitting on
the homepage and the filename is not specified in the document URL?

Thanks in advance,

--Diarmaid.
 
E

Evertjan.

Diarmaid wrote on 12 mei 2004 in comp.lang.javascript:
The problem I have is that the URL returned by document.URL (and
location.href) does not include the filename when I'm sitting on the
homepage. This means that when I compare the nav link with the
document URL, I don't get a match.

Eg:
document.URL and location.href returns "http://mydomain.com/"
The navigation link is "http://mydomain.com/index.html"

How can I find out the current document's filename if I'm sitting on
the homepage and the filename is not specified in the document URL?

lhref = document.URL;
if (/\/$/.test(lhref)) lhref += "index.html";
alert(lhref);

This will also do for all [sub]directories where index.html is the default.
 
E

Evertjan.

Balaji. M. wrote on 12 mei 2004 in comp.lang.javascript:
lhref = document.URL;
if (/\/$/.test(lhref)) lhref += "index.html";
alert(lhref);

This will also do for all [sub]directories where index.html is the
default.

Sometimes, default.htm, default.asp can also be used

Yes, but ...

clientside there is no way to see which default file is used.

Normally
index.htm,index.html,index.asp
default.htm,default.html,default.asp
etc.

this should not be a problem for clientside coding on the page, since you
will know what page you are coding on, unless you have a linked script.

why not try this:

<script type="text/javascript">var thispagenameis = "index.html"</script>
<script type="text/javascript" src="/lib/mylib.js"></script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top