I have a javascript file named main.js.
Inside main.js I want to get the absolute path of this current file, something like:
http://server/app/main.js
http://server/app/script/main.js
What is the fastest way to get the absolute path?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can investigate script collection at:
For each element in the returned
scriptsarray you can access itssrcattribute.The currently executing include file will always be the last one in the
scriptsarray. So you can access it atscripts[scripts.length-1].Of course this will only work at time of initial code run and would not be useful for example within a function that is called after initial script is loaded, so if you need the value available later, you would need to save it to a variable.