url - Path to included Javascript page -
How do I get a complete or site-relative path for an included JavaScript file?
I know it can be done in PHP, ( __ file __
, I think). Even for an included page, any path can be seen (in the included file). Is there any way to keep this awareness in Javascript itself?
I know that I can get the Page URL but need to get JS URL.
Example Javascript needs to modify the source of an image on the page. I know that the image is related to the Javascript file. I do not know where the Javascript page is in relation to.
& lt; Body & gt; & Lt; Img id = "img0" src = "" & gt; & Lt; Script src = "js / imgMaker / myscript.js" & gt; & Lt; / Script & gt; & Lt; / Body & gt; Function fixPath () {$$ ("# img0") [0] .set ('src', 'js / imgmaker / images / main.jpg'); }
Please do not tell me for the restructuring of my function - the requirement of the example is simple to explain, in the real case, an underlying class is being distributed and people will not Can put in the folder.
I used to read only the source of the script element, but the class can be part of any number of javascript files, so I can not know what the element looks like. There is no concept of file names in javascript ( not jscript)
It was developed for Netscape in those days. Therefore not __ file __
is a feature or something similar.
The closest you can come to these are two possibilities:
-
You have already mentioned: All of the JS files
src attributes and try to know which is the right.
Make this an essential option, the path of the images must be embedded in the embedded HTML file. If not set, then use the appropriate and well documented default:
& lt; Script type = "text / javascript" & gt; Var option = {'path_to_images': '/ static / images /' // '/ js / img /' default for;); & Lt; / Script & gt;
Comments
Post a Comment