Link to home
Start Free TrialLog in
Avatar of Ugi_Fletzet
Ugi_FletzetFlag for Israel

asked on

javascript code that get the included script path

I have html file like this:

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

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.

Thanks
Avatar of markhoy
markhoy
Flag of United Kingdom of Great Britain and Northern Ireland image

Hi Ugi_Fletzet,

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

TTFN,

chapatti
Avatar of Ugi_Fletzet

ASKER

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.
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:
<HTML>
 <HEAD>
   <script Language="JavaScript" Src="xxxx/yyyy/zzz.js" id="qqq"></script>
   </HEAD>
   .
   .
   .
</HTML>

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.
Just go to 'Community Support' (2nd last topic on the left menu) and post a question requesting this question be deleted and points refunded.
thanks
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial