Solved

How to refer relative path in JavaScript?

Posted on 2004-03-24
5
1,132 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 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

Industry Leaders: 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

Suggested Solutions

Title # Comments Views Activity
Jquery form 9 44
arrays and buttons with user input 2 34
assigning javascript variable to php variable 8 43
Looking for solution to pass data to 3rd-party web platform? 4 33
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

730 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