Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to retrieve the homepage filename when filename doesn't exist in URL

Reply
Thread Tools

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

 
 
Diarmaid
Guest
Posts: n/a
 
      05-12-2004
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.
 
Reply With Quote
 
 
 
 
kaeli
Guest
Posts: n/a
 
      05-12-2004
In article <(E-Mail Removed) >, elev43
@yahoo.com enlightened us with...
>
> 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?
>


Make a default. If no filename is specified, it's the home page.



--
--
~kaeli~
Why do people who know the least know it the loudest?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      05-12-2004
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.



--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      05-12-2004
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>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Retrieve url's of all jpegs at a web page URL grimmus Python 3 09-16-2009 05:12 AM
Does my object exist? So why its HWND doesn't exist? That's a question... (CMonthCalCtrl control) LT C++ 7 07-25-2004 07:08 PM
In Schema, how to say "If one element exist, another element must exist"? Y.S. XML 3 09-17-2003 02:51 PM
Help:Why can't I use namespace System.Web? It is said that this namespace doesn't exist. But it should exist. ASP .Net 1 07-29-2003 04:31 PM



Advertisments