Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I get the URL of the current page?

Status
Not open for further replies.

gdrenfrew

Programmer
Aug 1, 2002
227
GB
I'm trying to use the URL of pages in a javascript include file. The URL is matched to another string and is therefore case-sensitive.

I've been using Request.ServerVariables("URL") to get the url, but I've found that the url string changes depending on the link that was followed to get to the page.

Is there an object I can reference which holds the "true" URL of the page, not the one that was followed to get to the current page?

Failing that, can I turn off casesensitivity in javascript(!)?

Thanks
Graeme
UK
 
document.URL says "undefined". Document.URLUencoded returns the contents of the querystring (which I don't want).

 
That doesn't really work either.

If my asp page is in /Project1/Pages/myPage1.asp
and i link to it via response.redirect "/prOjEct1/pAges/myPage1.asp", that rather weird looking string becomes the document.location.pathname and document.URL too.

Can I find out what directory path my file is in (and there use the directory's location string)?

I guess I could go thru all the pages which link to my page and ensure they refer to the url in the correct case...

Thanks

 
here's a bit of code to spill out all the server variables available to ASP... check them out, and you'll find the variable you're after:
Code:
<!-- Show all server variables -->
<table border=&quot;1&quot;>
  <tr>
    <th>Server Variable</th>
    <th>Value</th>
  </tr>
<%For Each Item In Request.ServerVariables 
  if left(Item, 3) <> &quot;ALL&quot; then%> 
  <tr>
    <td><%= Item %></td>
    <td><%= Request.ServerVariables(Item) %></td>
  </tr>
  <%end if
Next%>
</table>
 
Also, is the case vitally important, do you have pages or directories named like &quot;PaGe.htm&quot; and &quot;pAgE.htm&quot;?, or is it just failing in your comparisons due to typing inconsistencies...?

Why not use
Code:
LCase(varURL)
(in vbscript) to get it in all-lowercase,

or, in javascript,
Code:
varURL.toLowerCase
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top