473,704 Members | 2,727 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 18237
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
7036
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
8766
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 usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8684
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9134
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8975
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5930
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4438
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4699
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3134
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
3
2078
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.