~/ equivalent in javascript

Vikram picture Vikram · May 21, 2009 · Viewed 26.2k times · Source

Any smart way of doing a "root" based path referencing in JavaScript, just the way we have ~/ in ASP.NET?

Answer

MiffTheFox picture MiffTheFox · May 21, 2009

Have your page generate a tag with something like:

<link rel="home" id="ApplicationRoot" href="http://www.example.com/appRoot/" />

Then, have a function in JavaScript that extracts the value such as:

function getHome(){
    return document.getElementById("ApplicationRoot").href;
}