Solved

How to refer relative path in JavaScript?

Posted on 2004-03-24
5
1,125 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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, the quoted word should read "realm" and not "real"

0
 
LVL 1

Author Comment

by:miyahira
Comment Utility
Thank you very much, Zvonko
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
You are welcome.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now