JavaScript relative path absolute path conversion

Converting Relative/Absolute Paths in JavaScript

A note on how to convert relative/absolute paths in JavaScript. Use JavaScript like this using document.createElement. console.log(absolutePath('hoge'));

Shou Arisaka
1 min read
Nov 11, 2025

A note on how to convert relative/absolute paths in JavaScript. Use JavaScript like this using document.createElement.

var absolutePath = function(href) {
    var link = document.createElement("a");
    link.href = href;
    return link.href;
}
console.log(absolutePath('hoge')) ;

By doing this, you can convert relative paths to absolute paths.

Share this article

Shou Arisaka Nov 11, 2025

๐Ÿ”— Copy Links