Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to refer relative path in JavaScript?

Posted on 2004-03-24
5
Medium Priority
?
1,140 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 280 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

636 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