Relative & absolute path question (JavaScript, mostly)

A

Alex

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
 
V

VK

How should I set the path in JavaScript ?

Same way as everywhere else I guess. Either you have an absolute link
or relative link, in the latter case the relative links are resolved
into absolute ones either by the page URL or - if specified - by base
URL.

Give the exact URL of page where the dynamic link is located and the
exact URL you want to navigate to on click. This way the best solution
can be siggested.
 
A

Alex

Same way as everywhere else I guess. Either you have an absolute link
or relative link, in the latter case the relative links are resolved
into absolute ones either by the page URL or - if specified - by base
URL.

Give the exact URL of page where the dynamic link is located and the
exact URL you want to navigate to on click. This way the best solution
can be siggested.

Thanks a lot, VK, it worked ! :))
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top