javascript get current directory

var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));

3
1
Mjfv 75 points

                                    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';
}

3 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
command to retrieve the current working directory in javascript js get folder of current script js get current dir javascript detect current directory print current dir js get current folder in javascript how to get current directory's path in javascript how to get current dir from js path current directory in javascript javascript how to get the current directory javascript get current directory path current directory location in js javascript get current working directory javascript get folders in directory javascript get directory get current dir javascript JS current folder current directory js get current working directory javascript get current directory javascript current dir javascript how to get current directory of a javascript file how to get the directory of a js file javascript show current directory javascript get current directory url js get current directory js get current folder get current directory path js get current dir path js how to get current dir in js javascript current folder javascript print current directory wscript get current directory get current directory js current directory javascript how to get current directory in js get the current directory in javascript javascript echo current directory get current working directory js Javascript current directory js current directory javascript get current folder name JavaScript get folder path js script How to get currebnt dir in js javascript get current directory javascript get path of current script javascript get current folder javascirpt get own path js get current folder name get the script directory from src javascript js script from path
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source