473,549 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the Javascript file name from a function inside the file.

I know the subject might be confusing. I am no beginner with
javascript but I haven't been able to figure out how to get the
javascript file name from code inside the file. So you have an HTML
doc with script tag who's source is a javascript file.

<HTML>
<script src="javascript .js"></script>
</HTML>

Javascript.js
-------------
code to get the javascript.js file name?

Is there a way to get the filename in which the code is being executed?
Thanks

Jul 23 '05 #1
21 18171
JRS: In article <11************ **********@z14g 2000cwz.googleg roups.com>
, dated Thu, 16 Dec 2004 10:54:43, seen in news:comp.lang. javascript,
ry******@yahoo. com posted :
I know the subject might be confusing. I am no beginner with
javascript but I haven't been able to figure out how to get the
javascript file name from code inside the file. So you have an HTML
doc with script tag who's source is a javascript file.

<HTML>
<script src="javascript .js"></script>
</HTML>

Javascript.j s
-------------
code to get the javascript.js file name?

Is there a way to get the filename in which the code is being executed?


Put var ThisIs = "javascript .js"
inside file javascript.js - or try rephrasing the question.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #2
ry******@yahoo. com wrote:
I know the subject might be confusing. I am no beginner with
javascript but I haven't been able to figure out how to get the
javascript file name from code inside the file. So you have an HTML
doc with script tag who's source is a javascript file.

<HTML>
<script src="javascript .js"></script>
</HTML>

Javascript.js
-------------
code to get the javascript.js file name?

Is there a way to get the filename in which the code is being executed?


IE and Opera support the document.script s collection and you can query
its src property. Mozilla won't give it that easy.

In testing locally, IE gives just the filename, Opera gives the full path.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #3
ry******@yahoo. com wrote:
[...]

Is there a way to get the filename in which the code is being executed?
Thanks


In addition to the methods above, put this in a form:

<input type="button" value="click" onclick="
var m,
foundOne = false,
msg = '';
if (!(m = document.script s))
m = document.getEle mentsByTagName( 'script');
for (var i=0; i<m.length; i++) {
if(m[i].src) {
msg += '\n' + m[i].src;
foundOne = true;
}
}
(foundOne)? alert(msg):aler t('No script files');
">
Lightly tested in Firefox and IE, only works if either the scripts
collection or getElementByTag Name is supported. You may want to extend
it further for other cases.

--
Rob
Jul 23 '05 #4
Thanks for the idea but this is going to be for a templating class
system and the document name will be changing constantly. I would like
to try to automate the file name retrieval so it does not have to be
manually inputted.

Dr John Stockton wrote:
JRS: In article <11************ **********@z14g 2000cwz.googleg roups.com> , dated Thu, 16 Dec 2004 10:54:43, seen in news:comp.lang. javascript,
ry******@yahoo. com posted :
I know the subject might be confusing. I am no beginner with
javascript but I haven't been able to figure out how to get the
javascript file name from code inside the file. So you have an HTML
doc with script tag who's source is a javascript file.

<HTML>
<script src="javascript .js"></script>
</HTML>

Javascript.j s
-------------
code to get the javascript.js file name?

Is there a way to get the filename in which the code is being
executed?
Put var ThisIs = "javascript .js"
inside file javascript.js - or try rephrasing the question.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 © <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ

items, links.

Jul 23 '05 #5
Thanks for the idea but I fail to see how the document.script s object
can give me the name of the script that code is running in? The script
object contains an array of sciprt objects. Each script object has a
src property which has the script name but if there is more then 1
script file loaded how would you identify which script object you code
is running under - Given that your code does not know what the file
name is from an manually inputted variable?

Jul 23 '05 #6
Thanks for the idea Rob but again how can you retrieve the proper
script object from the code being executed. The idea is automate the
retrieval of the script file name from code executing with the file.
So if you could retrieve the file name from the executing code to
compare it to the src property of a script object in the scripts
collection then you wouldn't need to iterate through the scripts
collection in the first place.

Jul 23 '05 #7
<ry******@yahoo .com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I know the subject might be confusing. I am no beginner with
javascript but I haven't been able to figure out how to get the
javascript file name from code inside the file. So you have an HTML
doc with script tag who's source is a javascript file.

<HTML>
<script src="javascript .js"></script>
</HTML>

Javascript.js
-------------
code to get the javascript.js file name?

Is there a way to get the filename in which the code is being executed?
Thanks


It's not clear to me what you want.

"Is there a way to get the filename in which the code is being executed?"

You want to get the name of the JavaScript "include" file when?

Also, what if the following is the case?

<HTML>
<script src="javascript 1.js"></script>
<script src="javascript 2.js"></script>
</HTML>
Jul 23 '05 #8
Perhaps my first post was not clear so hopefully this should clear it
up.

You have a javascript file that is included via the script tag in an
HTML file like so.
<SCRIPT language='javas cript' src='somejavasc ript.js'></script>

At runtime any code in this javascript.js file will be executed. Is
there a way to programmaticall y via the code in the somejavascript. js
file to determine the javascript file name it came from. So the code in
the somejavascript. js file should determine that it is within the
somejavascript. js file. I know you could just code it in but where
attempting to automate this process hence the term programmaticall y.
Hope this clears up any confusion.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #9
"Ryan Hubbard" <ry******@yahoo .com> wrote in message
news:41******** **@127.0.0.1...
Perhaps my first post was not clear so hopefully this should clear it
up.

You have a javascript file that is included via the script tag in an
HTML file like so.
<SCRIPT language='javas cript' src='somejavasc ript.js'></script>

At runtime any code in this javascript.js file will be executed. Is
there a way to programmaticall y via the code in the somejavascript. js
file to determine the javascript file name it came from. So the code in
the somejavascript. js file should determine that it is within the
somejavascript. js file. I know you could just code it in but where
attempting to automate this process hence the term programmaticall y.
Hope this clears up any confusion.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

First, the following is the current standard:

<script type='text/javascript' src='somejavasc ript.js'></script>

Second, the following is not a true statement:

"At runtime any code in this javascript.js file will be executed."

It may declare functions that may or may not be executed.

Third, what's wrong with JRS' suggestion of just placing a variable in the
file that identifies the name of the file?

Fourth, could you be more clear about "where [sic] attempting to automate
this process"?
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

185
6903
by: jacob navia | last post by:
Hi We are rewriting the libc for the 64 bit version of lcc-win and we have added a new field in the FILE structure: char *FileName; fopen() will save the file name and an accessor function will return the file name given a FILE *. Questions: What would be the best name for this function?
0
7532
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7462
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7492
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6059
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1957
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1069
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
777
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.