473,686 Members | 2,318 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

determining the location of a script on the server? Firefox bug won't let me

Hi,

I'm hoping for a reason I'm wrong or an alternate solution...

I'd like to be able to dynamically include some javascript files. This
is like scriptaculous.j s library but their solution is broken in
Firefox 1.5.0.1 on OS X. What happens with the Scriptaculous library is
this

In the html document the author only has to include one line

<script type="text/javascript"
src="/javascripts/scriptaculous.j s"></script>

but scriptaculous.j s determines where scriptaculous.j s was from and
then add other lines to the html doc to src other JavaScript files. By
the end of scriptaculous.j s the html doc has something like

<script type="text/javascript"
src="/javascripts/scriptaculous.j s"></script>
<script type="text/javascript" src="/javascripts/effects.js"></script>
<script type="text/javascript" src="/javascripts/dragdrop.js"></script>

(All the scripts are in the same server directory.)

This is a good idea in scriptaculous because it insures that the
JavaScript files are src'ed in the correct order. Also, if the
implementation of scriptaculous library changes then the html docs that
use it are not broken. This may lead to too much javascript being
src'ed by the html doc but I'm not worried about that right now.

The problem with the method of determining from what domain and which
directory scriptaculous.j s came from in the first place cannot be used
twice in Firefox (ie for two separate libraries). I tried to play the
same trick but document.getEle mentsByTagName( 'script') will not let me
do it. I have tried to trim down the following example to show what I
want to do. It works in Safari. The divs backgrounds are green and red.
In Firefox only one has a background color. No errors or exceptions.
Firefox can never find the <script src="grof.js"> tag.

If you want to see the problem I found with Firefox more isolated
please see bugzilla
(https://bugzilla.mozilla.org/show_bug.cgi?id=331174). What I found was
the problem is that in firefox you cannot ask for the length of the
scriptTags variable below twice (grof.js, burp.js). Changing the
variable name (scriptTags) in only grof.js did not make a difference.

So what is another way to determine the location (url) of grof.js (and
burp.js) in the following example (or scriptaculous.j s in that library)
so that I can dynamically src the other js files in the libraries
(grof2.js)? I don't want to hardcode any locations.

Thanks for reading this far and I hope someone has a suggestion.

Peter
------------------- test.html -------------------

<html>
<head>

<script type="text/javascript" src="grof.js"></script>

<script type="text/javascript" src="burp.js"></script>
</head>
<body>
<div id="grof">Grof </div>
<div id="burp">Burp </div>
</body>
</html>
------------------- grof.js -------------------

var scriptTags = document.getEle mentsByTagName( "script");
for(var i=0;i<scriptTag s.length;i++) {
if(scriptTags[i].src && scriptTags[i].src.match(/grof\.js(\?.*)? $/))
{
var path = scriptTags[i].src.replace(/grof\.js(\?.*)? $/,'');
document.write( '<script type="text/javascript"
src="'+path+'gr of2.js"></script>');
}
}

------------------- grof2.js -------------------
function g(){
var burp = document.getEle mentById("grof" );
burp.style.back ground="green";
}

window.addEvent Listener("load" , g, false);
------------------- burp.js -------------------

var scriptTags = document.getEle mentsByTagName( "script");
for(var i=0;i<scriptTag s.length;i++) {
if(scriptTags[i].src && scriptTags[i].src.match(/burp\.js(\?.*)? $/))
{
// Firefox will never get in here because the if condition will
never be true.
var path = scriptTags[i].src.replace(/burp\.js(\?.*)? $/,'');
document.write( '<script type="text/javascript"
src="'+path+'bu rp2.js"></script>');
}
}

------------------- burp2.js -------------------

function b(){
var burp = document.getEle mentById("burp" );
burp.style.back ground="red";
}

window.addEvent Listener("load" , b, false);

Mar 21 '06 #1
4 2154
pe**********@gm ail.com wrote:
So what is another way to determine the location (url) of grof.js (and
burp.js) in the following example (or scriptaculous.j s in that library)
so that I can dynamically src the other js files in the libraries
(grof2.js)? I don't want to hardcode any locations.

Thanks for reading this far and I hope someone has a suggestion.


I don't quite follow all of what your are thinking to do. In
particular, if you call on your first js file to be loaded, why can't
it presume that the rest haven't been loaded, given that you are
defining one "gateway" to access all the files. In other words, all
anybody is ever supposed to write is <script
src="firstJSfil eToCall.js"> and that takes care of loading the rest,
which the HTML author is not supposed to care about.

But, if you argue some schizophrenia on the part of the file
identifications , you could test for the existence of a function or
variable you know to exist. For example, each script that you are
interested in could set itself (that is, its name) on
window.aIAmLoad ed.

Also, you could assign an id to each script as well as an onload so
that is perhaps another way to get to the script element you are
looking for. For example, you could put in properties
id="currentScri ptFileName" and
onload='bootstr apIterator("nex tScriptFileName ")', which function you'd
define in your first script file.

Could it be that the script loading has not settled? Perhaps you could
put in a
window.setTimeo ut(
function(){
var st = document.getEle mentsByTagName( "script");
alert(st.length )},100);

Does it make a difference whether you use document.write or DOM methods
(document.creat eElement...)?

Good luck,
Csaba Gabor from Vienna

Mar 21 '06 #2
Hi Csaba,

Thanks for taking the time to read all of my problem. And thanks for
the ideas. I still think there is a fundamental problem left unsolved.
I've inserted comments below.

Peter

Csaba Gabor wrote:
pe**********@gm ail.com wrote:
So what is another way to determine the location (url) of grof.js (and
burp.js) in the following example (or scriptaculous.j s in that library)
so that I can dynamically src the other js files in the libraries
(grof2.js)? I don't want to hardcode any locations.

Thanks for reading this far and I hope someone has a suggestion.
I don't quite follow all of what your are thinking to do. In
particular, if you call on your first js file to be loaded, why can't
it presume that the rest haven't been loaded, given that you are
defining one "gateway" to access all the files.


I could but there is a bigger plan behind my example. This may be
wasteful if the two gateway scripts are subsets of one big library.
This isn't my big problem now anyway.
In other words, all
anybody is ever supposed to write is <script
src="firstJSfil eToCall.js"> and that takes care of loading the rest,
which the HTML author is not supposed to care about.
Yes, but where are the rest of the scripts? This is my big problem.
Determining the location of the other scripts. I have the library
installed in a top level directory ("/javascripts/") on my web app but
I give the library to someone else they may install the library further
down the directory tree. The gateway file for the library needs a way
to locate all of the rest of the scripts.
For example, you could put in properties
id="currentScri ptFileName" and
onload='bootstr apIterator("nex tScriptFileName ")', which function you'd
define in your first script file.
I can't chain the files together in this case. But even if I could I
don't know the URL of the next script. I'm hoping I don't have to force
the library user into writing the whole URL in the initial script src
tag for their installation of the library. That would feel like
failure. There should be some workaround so the gateway script can
identify it's own URL and use this as a basis to determine the other
files' URLs.
Could it be that the script loading has not settled? Perhaps you could
put in a
window.setTimeo ut(
function(){
var st = document.getEle mentsByTagName( "script");
alert(st.length )},100);

Does it make a difference whether you use document.write or DOM methods
(document.creat eElement...)?


scriptaculous.j s says that document.create Element method doesn't work
in Safari. I haven't tried this yet but either way i still need to know
the locations of all the script files in the library.

Any other ideas about getting the script locations?

thanks again,
Peter

Mar 21 '06 #3
pe**********@gm ail.com wrote:
Csaba Gabor wrote:
pe**********@gm ail.com wrote:
So what is another way to determine the location (url) of grof.js (and
burp.js) in the following example (or scriptaculous.j s in that library)
so that I can dynamically src the other js files in the libraries
(grof2.js)? I don't want to hardcode any locations.
Yes, but where are the rest of the scripts? This is my big problem.
Determining the location of the other scripts. I have the library
installed in a top level directory ("/javascripts/") on my web app but
I give the library to someone else they may install the library further
down the directory tree. The gateway file for the library needs a way
to locate all of the rest of the scripts.
For example, you could put in properties
id="currentScri ptFileName" and
onload='bootstr apIterator("nex tScriptFileName ")', which function you'd
define in your first script file.
I can't chain the files together in this case. But even if I could I
don't know the URL of the next script. I'm hoping I don't have to force


I think I'm missing something here. Who does know the URL (or more
rather, file name) of the next script(s). In other words, once the
first file in your library is loaded, either that file should know the
rest of the scripts involved, or it should know the next one only and
the next one is responsible for knowing the 3rd one's name and so on.
Or is there something else going on? I assumed it was the second of
the two possibilities I mentioned since you were mentioning that you
were ensured sequential loading. If this is off, please correct me.
Not that it really would have changed my responses, I think.
the library user into writing the whole URL in the initial script src
tag for their installation of the library. That would feel like
So let me paraphrase what I think I read. I imagined that you had a
library (of several javascript files full of lots of fun code). And
that this library winds up on other people's servers - that is to say
that the javascript files wind up on someone's server who is intending
to use the library. Only it could be in an arbitrary location relative
to the HTML documents they are serving up. So you want them to be able
to have a minimally long src="..." in order to specify the location of
the first javascript file in the library. And that javascript file is
responsible for loading all the rest. But to do that, it needs to know
where it itself is, so that it can write a complete src for the
remaining SCRIPTS that it writes out. And it intends to do this by
finding the src for its own SCRIPT tag (and also window.location .href).
failure. There should be some workaround so the gateway script can
identify it's own URL and use this as a basis to determine the other
files' URLs.
Could it be that the script loading has not settled? Perhaps you could
put in a
window.setTimeo ut(
function(){
var st = document.getEle mentsByTagName( "script");
alert(st.length )},100);

Does it make a difference whether you use document.write or DOM methods
(document.creat eElement...)?


scriptaculous.j s says that document.create Element method doesn't work
in Safari. I haven't tried this yet but either way i still need to know
the locations of all the script files in the library.

Any other ideas about getting the script locations?


So is it not the case, that you only ever need to fish out one script
tag, really, that first one that the user/developer must code because
that will allow subsequent scripts to determine the location of all the
remaining script files?

In this case, won't placing an id=... allow that script element to be
recovered? I still think this is the one that bears most careful
examination.
<script type='text/javascript' id='PetersFunky Library'
onLoad="alert(d ocument.getElem entById('Peters FunkyLibrary'). id)"
src="..."></script>

Up to some months (a year?) ago, it was the case that in FF the SCRIPT
elements sat in the HEAD element off the HTML element
(=document.docu mentElement). But that is evidently no longer the case,
as I am now finding the SCRIPT elements under document.body, and not
necessarily directly under (if you wrap the SCRIPT in a DIV). It seems
to me that they were happy where they used to live and I don't see the
reason for their eviction. Nevertheless, perhaps directly walking all
the elements of document.body.c hildNodes and checking for
..nodeName=="SC RIPT" might have a shot at finding all the script
elements in the problem browser (though I don't give it good chances if
document.body.g etElementsByTag Name('SCRIPT') is failing).

Csaba

Mar 21 '06 #4
Casab,
So you want them to be able
to have a minimally long src="..." in order to specify the location of
the first javascript file in the library. And that javascript file is
responsible for loading all the rest. But to do that, it needs to know
where it itself is, so that it can write a complete src for the
remaining SCRIPTS that it writes out. And it intends to do this by
finding the src for its own SCRIPT tag (and also window.location .href).
Yes, exactly.
So is it not the case, that you only ever need to fish out one script
tag, really, that first one that the user/developer must code because
that will allow subsequent scripts to determine the location of all the
remaining script files?
Yes that is true. If two libraries are included then I need to do this
once for each library. That is where the scriptaculous idea fails in
firefox. Once the trick is used once then it can't be used again due to
a bug. It might be breaking other things too.

In this case, won't placing an id=... allow that script element to be
recovered? I still think this is the one that bears most careful
examination.
<script type='text/javascript' id='PetersFunky Library'
onLoad="alert(d ocument.getElem entById('Peters FunkyLibrary'). id)"
src="..."></script>
I was hoping to avoid adding anything on the part of the library user
but maybe it is necessary for now. If I can't find a cross browser
solution then I will try this.

Up to some months (a year?) ago, it was the case that in FF the SCRIPT
elements sat in the HEAD element off the HTML element
(=document.docu mentElement). But that is evidently no longer the case,
as I am now finding the SCRIPT elements under document.body, and not
necessarily directly under (if you wrap the SCRIPT in a DIV). It seems
to me that they were happy where they used to live and I don't see the
reason for their eviction. Nevertheless, perhaps directly walking all
the elements of document.body.c hildNodes and checking for
.nodeName=="SCR IPT" might have a shot at finding all the script
elements in the problem browser (though I don't give it good chances if
document.body.g etElementsByTag Name('SCRIPT') is failing).


I didn't know that there were such problems with the SCRIPT elements in
Firefox. Thanks for this suggestion. I tried direct walking
document.childN odes and it worked in Firefox!!! Now I don't even have
to check for script tags. I just look for any tag with a src with a
regular string match. This is great! Now I have to try on IE. Nail
biting time.

Below is my new burp.js which needs some clean up (and the old one for
reference).

Many thanks! I really appreciate your patients in helping me.

:D

Peter
------------------------------ new burp.js
-------------------------------------

function check_is_script (element){
if(element.src && element.src.mat ch(/burp\.js(\?.*)? $/)){
return element;
}

var children = element.childNo des;
for(var i=0;i<children. length;i++) {
var found = check_is_script (children[i]);
if (found != null) {
return found;
}
}

return null;
}

var asdf = check_is_script (document);
if(asdf != null) {
var path = asdf.src.replac e(/burp\.js(\?.*)? $/,'');
document.write( '<script type="text/javascript"
src="'+path+'bu rp2.js"></script>');
}
------------------------------ old burp.js
-------------------------------------

var scriptTags = document.getEle mentsByTagName( "script");
for(var i=0;i<scriptTag s.length;i++) {
if(scriptTags[i].src && scriptTags[i].src.match(/burp\.js(\?.*)? $/))
{
var path = scriptTags[i].src.replace(/burp\.js(\?.*)? $/,'');
document.write( '<script type="text/javascript"
src="'+path+'bu rp2.js"></script>');
}
}

Mar 21 '06 #5

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

Similar topics

14
37149
by: Frances Del Rio | last post by:
I'm trying to open a url in a new window while pg loads (but NOT in a pop-up..) I need to do sthg like // while pg is loading.. window.location ='page.html' // but I need this to open in a new blank window.. // (NOT in a pop-up, a regular new window..) can you do this?? thank you..
10
16579
by: Roland | last post by:
Hello, the example code is the following(the number in parentheses at the beginning are just for reference)(The complete HTML file is at the end of this article): (1)window.location = 'http://www.google.com'; (2)alert("I'm still here!"); (3)window.open("http://www.slashdot.com", "_blank");
13
1517
by: Razzbar | last post by:
Is there any to tell via javascript the "state" of a link? I mean, I'd like to be able to tell if a link has been followed or not. (hehe, I can hear shrill crys of "privacy!" in the distance...)
3
5172
by: David Hayes | last post by:
I've made tooltips work in Firefox*, but tooltip doesn't appear at the specified location until the SECOND time that the user passes the mouse over the location with the mouseover event. What I want is for the user to be able to put the mouse over text that gives a year (e.g., "(1932)", "(1946)" and "(1923)") and see the tooltip to the right and slightly beneath the year. (For the record -- this needn't concern the debugging effort --...
6
6299
by: baranabas | last post by:
I have looked, but I can't seem to find an explanation for the problem I am having. I have a page that show an image from another server. I want the image to refresh without refreshing my page. (My page has a huge flash movie on it that is sucking my bandwidth.) I have devised the solution below which works only in IE, but not if Firefox or Opera or Safari. I would really appreciate any help. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01...
18
8414
by: DartmanX | last post by:
Is there a simple way to determine if someone using Internet Explorer has completely disabled ActiveX controls? Jason
4
2151
by: Lachlan Hunt | last post by:
Hi, I'm looking for an interoperable method of determining the current background colour of an element that is set using an external stylesheet. I've tried: elmt.style.backgroundColor; but that only works if the colour has been set using the style attribute or previously set using script. I've also tried:
4
13080
by: Jeff Paffett | last post by:
I'm writing a file manager application using Ajax techniques and the client wants to be able to bookmark file searches. I send the search request to a remote server using a XMLHttpRequest and then write the search string to a # URL, either using window.location.href or window.location.hash. This works fine with no problems in IE and Firefox and works OK in Safari, except the browser goes into a permanent page loading state as soon as I...
2
2954
by: itmanager8815 | last post by:
I had a question regarding the use of document.location. I have the following script: <HTML> <BODY> <SCRIPT LANGUAGE=JAVASCRIPT> window.status=''; document.location='file://c:/myfolder/myfile';
0
8585
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
8517
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
8934
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...
1
8770
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8780
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
7603
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4309
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
4534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2947
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

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.