Javascript Relative Path
In a first html file, I use a variable categoryLinks : var categoryLinks = { 'Career prospects':'http://localhost/Landa/DirectManagers/511-HelenaChechik/Dim01.html', 'Compe
Solution 1:
It depends on the URL of the page you're loading them into, which you haven't shown, but you may want a leading /
:
var categoryLinks = {
'Career prospects':'/Landa/DirectManagers/511-HelenaChechik/Dim01.html'// Here ----------------^
...or possibly a leading ../
:
var categoryLinks = {
'Career prospects':'../Landa/DirectManagers/511-HelenaChechik/Dim01.html'// Here ----------------^^^
..or similar.
Basically:
Say you have
http://example.com/foo/page.html
and you have a relative link in it:
testing/stuff.html
That will replace page.html
, giving you:
http://example.com/foo/testing/stuff.html
If you didn't want to be in foo
, you'd either use a leading /
which means "Start at the root of the domain":
/testing/stuff.html
...or ..
which means "go up a level":
../testing/stuff.html
The ..
can be used more than once, so if you have the page:
http://example.com/this/is/deeply/nested.html
the relative link
../../test.html
gives you
http://example.com/this/test.html
Also note that the links will be relative to the HTML page they're in, not the JavaScript script file they're in.
Post a Comment for "Javascript Relative Path"