[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to refer relative path in JavaScript?

Posted on 2004-03-24
5
Medium Priority
?
1,142 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
Suggested Courses

872 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