Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple redundant javascripts in same page; none works....

Status
Not open for further replies.

atomas

Technical User
May 7, 2000
3
CA
Hi, i am an artist/web designer new to javascripting...<br>I do cut n paste and some syntax tweaking to make interesting actions in my web pages...<br><br>My problem of the day is:<br>Multiple redundant copies of same randomizer script on same page; none works...<br>One copy only of the script in page and it works fine....<br><br>I tried to modify the array and function names to fool the other script but no chance...<br>May look simplistic but i stumbled on this one...<br><br>Here is the script:<br><br>&lt;script language=&quot;JavaScript&quot;&gt;<br>&lt;!--<br>images = new Object;<br>function adArray() {<br>&nbsp;for (i=0; i*2&lt;adArray.arguments.length; i++) {<br>&nbsp;&nbsp;if (document.images) {<br>&nbsp;&nbsp;&nbsp;images<i> = new Image();<br>&nbsp;&nbsp;&nbsp;images<i>.src = adArray.arguments[i*2];<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;this<i> = new Object();<br>&nbsp;&nbsp;this<i>.src = adArray.arguments[i*2];<br>&nbsp;&nbsp;this<i>.href = adArray.arguments[i*2+1];<br>&nbsp;}<br>&nbsp;this.length = i;<br>}<br>function getAdNum() {<br>&nbsp;dat = new Date();<br>&nbsp;dat = (dat.getTime()+&quot;&quot;).charAt(8);<br>&nbsp;if (dat.length == 1)<br>&nbsp;&nbsp;ad_num = dat%ads.length;<br>&nbsp;else<br>&nbsp;&nbsp;ad_num = 0;<br>&nbsp;return ad_num;<br>}<br>&nbsp;<br><br>var num_ads_to_display = 5;<br><br>var ads = new adArray(<br>&quot;images/red.gif&quot;,&quot;index.htm&quot;,<br>&quot;images/green.gif&quot;,&quot;green.htm&quot;,<br>&quot;images/yellow.gif&quot;,&quot;yellows.htm&quot;,<br>&quot;images/violet.gif&quot;,&quot;violet.htm&quot;,<br>&quot;images/blue.gif&quot;,&quot;blue.htm&quot;);<br><br>var ad_num = getAdNum(); <br><br>function writeAd(i) {<br>&nbsp;document.write('&lt;A HREF=&quot;'+ads[(ad_num+i)%ads.length].href<br>&nbsp;+'&quot;&gt;&lt;IMG SRC=&quot;'+ads[(ad_num+i)%ads.length].src+'&quot; '<br>&nbsp;+'width=50 height=50 border=0 name=&quot;js_ad'+i+'&quot; vspace=0&gt;&lt;/A&gt;&lt;br&gt;');<br>}<br><br><br>for(i=0;i&lt;num_ads_to_display;i++)<br>&nbsp;writeAd(i);<br>link_num = document.links.length-num_ads_to_display;<br><br>function rotateSponsor() {<br>&nbsp;if (document.images) {<br>&nbsp;&nbsp;ad_num = (ad_num-1+ads.length)%ads.length;<br>&nbsp;&nbsp;for (i=0; i&lt;num_ads_to_display; i++) {<br>&nbsp;&nbsp;&nbsp;eval(&quot;document.js_ad&quot;+i+&quot;.src = ads[(ad_num+i)%ads.length].src;&quot;);<br>&nbsp;&nbsp;&nbsp;document.links[link_num+i].href = ads[(ad_num+i)%ads.length].href;<br>&nbsp;&nbsp;}<br>&nbsp;&nbsp;setTimeout(&quot;rotateSponsor()&quot;,2000);<br>&nbsp;}<br>}<br>setTimeout(&quot;rotateSponsor()&quot;,2000);<br><br>// --&gt;<br>&lt;/script&gt; <br><br><br>Thanx in advance <br>Atomas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top