Relative & absolute path question (JavaScript, mostly)

R

Radu

Hi.

I have files in the "Scorecard Previews" subfolder of the virtual path
of my app,
the absolute path being

C:\Data\Ordering Process\Scorecard Previews\


I have a javascript function which changes the href of an <a>
depending on some selection in a combo. If in the javascript function
I set the href like this:

hLink.href="/Scorecard Previews/"+ cbo.options[index].text +
".doc"

the <a> points to something like

http://localhost:1218/Scorecard Previews/MyScorecard_1.doc

which is not correct - it should be

http://localhost:1218/Ordering Process/Scorecard
%20Previews/MyScorecard_1.doc

(I'm missing part of the path) - the path to the application.


If i set the href like this:

hLink.href="~/Scorecard Previews/"+ cbo.options[index].text
+ ".doc"

the <a> points to something like

http://localhost:1218/Ordering Process/~/Scorecard
%20Previews/MyScorecard_1.doc

which is not correct - it should be

http://localhost:1218/Ordering Process/Scorecard
%20Previews/MyScorecard_1.doc

(I have an extra "~" character).

How should I set the path in JavaScript ?

In VB.net (code behind) it has been very simple:

cmdOpenScorecardPreview.NavigateUrl = "~/Scorecard
Previews/" & strSelectedScorecard


Thanks a lot
Alex
 
B

bruce barker

unfortunatly iis does not support the "~" path specification (which is
really a unix feature). asp.net sorta supports it. when a server side
control renders a url it translates the "~" path to the vdir path.

to do this in javascript you can use a relative path:

hLink.href="Scorecard Previews/"
+ cbo.options[index].text + ".doc"

which will work if the current page is in the basedir. if its in a
subfolder you can navigate up "../Scorecard Previews".

to a browser "/path", means server/path.

-- bruce (sqlwork.com)
 
R

Radu

unfortunatly iis does not support the "~" path specification (which is
really a unix feature). asp.net sorta supports it. when a server side
control renders a url it translates the "~" path to the vdir path.

to do this in javascript you can use a relative path:

hLink.href="Scorecard Previews/"
+ cbo.options[index].text + ".doc"

which will work if the current page is in the basedir. if its in a
subfolder you can navigate up "../Scorecard Previews".

to a browser "/path", means server/path.

-- bruce (sqlwork.com)


I have files in the "Scorecard Previews" subfolder of the virtual path
of my app,
the absolute path being
C:\Data\Ordering Process\Scorecard Previews\
I have a javascript function which changes the href of an <a>
depending on some selection in a combo. If in the javascript function
I set the href like this:
hLink.href="/Scorecard Previews/"+ cbo.options[index].text +
".doc"
the <a> points to something like

which is not correct - it should be

(I'm missing part of the path) - the path to the application.
If i set the href like this:
hLink.href="~/Scorecard Previews/"+ cbo.options[index].text
+ ".doc"
the <a> points to something like

which is not correct - it should be

(I have an extra "~" character).
How should I set the path in JavaScript ?
In VB.net (code behind) it has been very simple:
cmdOpenScorecardPreview.NavigateUrl = "~/Scorecard
Previews/" & strSelectedScorecard
Thanks a lot
Alex- Hide quoted text -

- Show quoted text -

Thank you, Bruce, it worked :))) Have a great weekend !
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top