PDA

View Full Version : Multiple Javascript on Page


waytogo13
10-29-2002, 07:18 PM
Is there any limit as to the number of Javascript(s) one can have on a web site page? I'm seeing a pop up I added to a test page... but not when I try to add it to another page with multiple things (javascript applets) already there...?

Here's the page that is not showing it:

Link that is not showing the pop up I added (http://www.angelfire.com/ny3/hhffl1313)

beetle
10-29-2002, 07:28 PM
No limit. However, you cannot have any conflicting variable names and/or function names between the scripts...(in other words, both scripts might be trying to use the same variable...so they mess eachother up...)

waytogo13
10-29-2002, 07:50 PM
I guess I'm still unclear....

As I DO have other javascripts on that page.... what would constituite a conflict... and can I rectify that?

Thanks

beetle
10-29-2002, 07:54 PM
Exmaple...

Script 1<script>
var i;
for (i=0; i<10; i++)
window.status += i;
</script>Script 2var i='Hello';
alert(i);
</script>See how they both use the common global variable i? Script 1 is using i to loop, but Script 2 gives it a string value, which will break the loop in Script 1.

Make sense?

waytogo13
10-29-2002, 08:09 PM
Thanks... I'm pretty good at copying and pasting....(stealing?borrowing?) but understanding is another thing...

Am I out of luck if I have the two similar variables for instance, however?

beetle
10-29-2002, 08:23 PM
No, not out of luck, but maybe in some trouble.

The problem with so many of the free scripts out there, is they poison the 'global namespace', such as the example above. It can be fixed, but it is usually a tedious manual process of checking global variables and function names in one script against those in the other, and updating/changing/re-writing accordingly.

If you can't do this, I'd suggest you find someone who has the knowledge, time, and desire, because, with all due respect, I don't :D

waytogo13
10-29-2002, 08:38 PM
Thanks for your speedy replies...

I imagine I would make people with true Javascript knowledge sick: looking at the jumble of javascript I throw on to my pages... if it works, I keep it, if it doesn't I don't have much skill in troubleshooting.

Still lots of fun... and now I'm fooling with DHTML which is very impressive stuff also!