javascript code that get the included script path

Posted on 2003-03-12
Medium Priority
Last Modified: 2013-11-18
I have html file like this:

        <script Language="JavaScript" Src="xxxx/yyyy/zzz.js"></script>

I also have the included JavaScript file "zzz.js" in xxxx/yyyy folder.

My question:
is there any javascript code that will be inside the included file "zzz.js" that gets the path name ("xxxx/yyyy") ?
location.href will not work, because it's related to the whole document url and not to the included script url

it should support JavaScript 1.2 and IE browsers.

Question by:Ugi_Fletzet
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8122480
Hi Ugi_Fletzet,

What are you trying to do?
Maybe I can come up with a work-around.



Author Comment

ID: 8123264
Hi chapatti,
i need a piece of javascript code (that will be inside the included .js file) that will return the path of this .js file.
"var path=location.href" will not work, because this will return the path of the parent html file and not the path of the included js file.
I'm sure there is an easy way to find it.
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.


Author Comment

ID: 8123573
I found the answer by myself...

the answer is: document.scripts(x).src
where x is the id of the script or the index of the script.

for example, I need to change the html file to:
   <script Language="JavaScript" Src="xxxx/yyyy/zzz.js" id="qqq"></script>

and later in the .js file I can do like that:
var path=document.scripts('qqq').src

Now, I need to give that points back to myself, but unfortunately, I think that I can't do that. if anyone know how can I do that, please tell me.
LVL 12

Expert Comment

ID: 8124200
Just go to 'Community Support' (2nd last topic on the left menu) and post a question requesting this question be deleted and points refunded.

Author Comment

ID: 8124253

Accepted Solution

SpideyMod earned 0 total points
ID: 8124359
PAQ'd and points refunded.

Community Support Moderator @Experts Exchange

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question