Mission & Code
Sometimes you just need a way of determining the absolute path from a specified relative path. When you are in this situation, you may use the following code:
(function() {
var img = new Image();
getAbsPathFor = function(relativePath) {
img.src = relativePath;
return img.src;
};
})();
Parameters
- relativePath:
The relative (as a string) that you would like to retrieve the corresponding absolute path for.
Example
To use this code, you could do something similar to the following:
// Show me the absolute path for "../".
alert('The absolute path for "../" is "' + getAbsPathFor('../') + '".');
// Show me the absolute path for "/test/".
alert('The absolute path for "/test/" is "' + getAbsPathFor('/test/') + '".');
Final Notes
This code is only for web browser, and/or HTA use. This code probably won’t work in a stand-alone desktop JScript.