JavaScript mendapatkan direktori saat ini
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));
Cautious Cicada
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));
var scripts= document.getElementsByTagName('script');
var path= scripts[scripts.length-1].src.split('?')[0]; // remove any ?query
var mydir= path.split('/').slice(0, -1).join('/')+'/'; // remove last filename part of path
function doSomething() {
img.src= mydir+'../images/myimage.jpeg';
}