document.URL

P

Peter UG

Hi all,

the simple script to print the current URL is fine:

<script language="JavaScript">

<!--

document.write(document.URL)

//-->

</script>



but as my cgi-script receiving the URL referrer needs the actual page name,
anyone browsing a top level directory without the index.html as in:

http://site.com/about/

and the cgi-script will not work.

So how can this javascript be done so if the document.URL end in / the
script adds index.html.

Any help from experts really appreciated!

Peter.
 
B

Brian Genisio

Peter said:
Hi all,

the simple script to print the current URL is fine:

<script language="JavaScript">

<!--

document.write(document.URL)

//-->

</script>



but as my cgi-script receiving the URL referrer needs the actual page name,
anyone browsing a top level directory without the index.html as in:

http://site.com/about/

and the cgi-script will not work.

So how can this javascript be done so if the document.URL end in / the
script adds index.html.

Any help from experts really appreciated!

Peter.


It is difficult to know for sure that index.html is the page you are on.
This is because the browser is never told.

When you make a page request, such as http://site.com/about/ , the
server has a default document assigned. The server might have
index.html, or index.htm, or default.asp, or whatever the server is
convigured to say.

The server uses the default value, and reads the file, and returns data
for the original request. So, one thing you can do, on the server, is
do a 303 redirect of the page to the default. It depends on the server.
Whatever you use, your browser can never know what the default page is
named, unless it is specifically told in some way.

Brian
 

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
474,102
Messages
2,570,645
Members
47,245
Latest member
ShannonEat

Latest Threads

Top