Solved

How to refer relative path in JavaScript?

Posted on 2004-03-24
5
1,126 Views
Last Modified: 2008-01-09
Instead of :
location.href="http://192.168.200.5/MyWebCarpet/wf_Form01.aspx"

is there any way to refer a relative path ?
Something like:
location.href="/MyWebCarpet/wf_Form01.aspx"
or
location.href=Server.MapPath("/MyWebCarpet/wf_Form01.aspx")
0
Comment
Question by:miyahira
  • 4
5 Comments
 
LVL 63

Expert Comment

by:Zvonko
ID: 10671730
the first one is good:
window.location.href="/MyWebCarpet/wf_Form01.aspx"

Because window is root object you can ommit it.

0
 
LVL 63

Accepted Solution

by:
Zvonko earned 70 total points
ID: 10671790
You did not ask, but there is also another relative position.
When your new refrence start with a forward slash (like in your example), then is the reference relative to server root.
When your reference does NOT start with an forward slash, then is the reference relative to actual page directory position (the last forward slash).

Let say, your actual page is URL is: http://192.168.200.5/MyWebCarpet/some.aspx
Then you can assign the new page relative to last "real", that is the last forward slash:
window.location.href="wf_Form01.aspx"

If you have several slashes inbetwean, then you have go back and forth. With two dots you get one lever back, and from there you can go some directory forward andf so on.

Like this:
window.location.href="../myAppDir/wf_Form01.aspx"

You see?


0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10671810
Sorry, the quoted word should read "realm" and not "real"

0
 
LVL 1

Author Comment

by:miyahira
ID: 10671879
Thank you very much, Zvonko
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 10672184
You are welcome.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now