Forum Moderators: open
<SCRIPT LANGUAGE=JAVASCRIPT>
<!--
ShowRandomBannerAd();
//-->
</SCRIPT>
above this in the HTML code:
<SCRIPT LANGUAGE=JAVASCRIPT>
<!--
function ShowRandomBannerAd(){
blah blah blah
//-->
</SCRIPT>
The reason I have to do it this way is because of certain restrictions by a third party software. Would that work or not?
In the example you give, it would fail. However the following would be ok.
function fna()
{ fnb() }
function fnb()
{ alert('yippee') }
fna();
This would be ok because when fna() is called, both functions are known.
Kaled.
This also works, even though the declarations of both functions ar below the call.
[b]
fna();function fna(){ fnb() }
function fnb(){ alert('yippee') }
[/b]
There are two necessary conditions for this:
1. The function must be declared with this kind of syntax (the 'usual' kind)
- function functionName(){ ... }
2. The function definition must be in the same script block as the call (or one above, natch)
#2 Is why web_young's code will cause an error.
1. Simply copy the function to the top block, where it can be executed. It will be overriden by the 'original' later.
<script>
ShowRandomBannerAd();
function ShowRandomBannerAd(){
blah blah blah
</script>
<script>
function ShowRandomBannerAd(){
blah blah blah
</script>
or 2. Estimate a reasonable code-download margin, and put it into a timer.
In the top block..
setTimeout('ShowRandomBannerAd()',1000) or 3. That's leaving things to chance a little. You could go all the way, and have a loop that tests for the function, and executes it when found. This way the function will be executed sooner, and there's no chance of attempting to execute it before it exists.
<script>
waitForFn("testFunction",200)function waitForFn(fnName, delay)
{
var intv = setInterval(repeat, delay)
function repeat(){
if(window[fnName]){ window[fnName](); clearInterval(intv); }
}
}
</script><script>
function testFunction(){
alert('hello')
}
</script>
1. Simply copy the function to the top block, where it can be executed. It will be overriden by the 'original' later.<script>
ShowRandomBannerAd();
function ShowRandomBannerAd(){
blah blah blah
</script><script>
function ShowRandomBannerAd(){
blah blah blah
</script>
But it doesn't seem like the first function is being overriden by the second function. Should the second function override the first? Thanks again for your help with this.
So I guess:
<script>
ShowRandomBannerAd(); // alerts: 1
function ShowRandomBannerAd(){
alert(1)
}
</script>
<script>
function ShowRandomBannerAd(){
alert(2)
}
// below function defn
ShowRandomBannerAd(); // alerts: 2
</script>
If not, try the timer.
PRINT "<script language='JavaScript1.2'>"
NEWLINE
PRINT "<!--"
NEWLINE
PRINT "function ShowRandomBannerAd(){"
NEWLINE
PRINT " var BannerCount=4;"
NEWLINE
PRINT "<!-- Change BannCount to -1 to turn banners off --!>"
NEWLINE
PRINT " var RandomNumber=Math.floor(Math.random()*BannerCount)+1;"
NEWLINE
PRINT " if (RandomNumber==1){"
NEWLINE
PRINT " ShowBannerAd('ad_billpay2.swf','ad_billpay.jpg',475,60,'billpayer/index.htm');"
NEWLINE
PRINT " }"
NEWLINE
PRINT " else if (RandomNumber==2){"
NEWLINE
PRINT " ShowBannerAd('ad_loanapp2.swf','ad_loanapp.jpg',475,60,'loanapplication/index.htm');"
NEWLINE
PRINT " }"
NEWLINE
PRINT " else if (RandomNumber==3){"
NEWLINE
PRINT " ShowBannerAd('ad_visacard.swf','ad_visacard.gif',475,60,'visa/credit.htm');"
NEWLINE
PRINT " }"
NEWLINE
PRINT " else if (RandomNumber==4)"
NEWLINE
PRINT " {"
NEWLINE
PRINT " ShowBannerAd('ad_estatement.swf','treebanner.jpg',450,58,'services/unet.htm#estatements');"
NEWLINE
PRINT " }"
NEWLINE
PRINT "}"
NEWLINE
PRINT "//-->"
NEWLINE
PRINT "</SCRIPT>"
PRINT "function ShowBannerAd(MovieName,ImageName,AdWidth,AdHeight,DestURL){"
NEWLINE
PRINT " if (FlashSupported && MovieName!=''){"
NEWLINE
PRINT " document.writeln('<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>'+"
NEWLINE
PRINT " '<TR VALIGN=BOTTOM><TD>');"
NEWLINE
PRINT " document.writeln("
NEWLINE
PRINT " '<OBJECT CLASSID='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'');"
NEWLINE
PRINT " if (!(navigator.userAgent.toLowerCase().indexOf('msie 6.0')!=-1))"
NEWLINE
PRINT " document.writeln(' CODEBASE='http://download.macromedia.com/pub'+"
NEWLINE
PRINT " '/shockwave/cabs/flash/swflash.cab#5,0,0,0'');"
NEWLINE
PRINT " else"
NEWLINE
PRINT " document.writeln(' CODEBASE=''');"
NEWLINE
PRINT " document.writeln(' WIDTH='+AdWidth+' HEIGHT='+AdHeight+' ALIGN=TOP>');"
NEWLINE
PRINT " document.writeln(' <PARAM NAME='SRC' VALUE='/ns-icons/'+MovieName+''>');"
NEWLINE
PRINT " document.writeln(' <PARAM NAME='QUALITY' VALUE='high'>');"
NEWLINE
PRINT " document.writeln(' <PARAM NAME='LOOP' VALUE='TRUE'>');"
NEWLINE
PRINT " document.writeln(' <EMBED SRC='/ns-icons/'+MovieName+"
NEWLINE
PRINT " '' PLUGINSPAGE='https://www.macromedia.com/shockwave/download/'');"
NEWLINE
PRINT " document.writeln(' TYPE='application/x-shockwave-flash' WIDTH='+"
NEWLINE
PRINT " AdWidth+' HEIGHT='+AdHeight+' QUALITY='high'');"
NEWLINE
PRINT " document.writeln(' ALIGN='TOP' LOOP='TRUE' VSPACE=0>');"
NEWLINE
PRINT " document.writeln(' </EMBED>');"
NEWLINE
PRINT " document.writeln('</OBJECT>');"
NEWLINE
PRINT " if (DestURL!=''){"
NEWLINE
PRINT " document.writeln('</TD><TD valign=middle>'+"
NEWLINE
PRINT " '<A HREF=''+DestURL+''><IMG SRC='/ns-icons/learnmore.gif'');"
NEWLINE
PRINT " document.writeln(' WIDTH=84 HEIGHT=19 BORDER=0 HSPACE=8 VSPACE=2></A>');"
NEWLINE
PRINT " }"
NEWLINE
PRINT " document.writeln('</TD></TR></TABLE>');"
NEWLINE
PRINT " }"
NEWLINE
PRINT " else if (!(navigator.appName &&"
NEWLINE
PRINT " navigator.appName.indexOf('Netscape')>=0 &&"
NEWLINE
PRINT " navigator.appVersion.indexOf('2.')>=0) &&"
NEWLINE
PRINT " ImageName!=''){"
NEWLINE
PRINT " if (DestURL!=''){"
NEWLINE
PRINT " document.write('<A HREF=''+DestURL+''>');"
NEWLINE
PRINT " }"
NEWLINE
PRINT " document.write('<IMG SRC='/ns-icons/'+ImageName+'' WIDTH='+AdWidth+"
NEWLINE
PRINT " ' HEIGHT='+AdHeight+' BORDER=0>');"
NEWLINE
PRINT " if (DestURL!=''){"
NEWLINE
PRINT " document.write('</A>');"
NEWLINE
PRINT " }"
NEWLINE
PRINT " }"
NEWLINE
PRINT "}"
NEWLINE
Thanks for all your help!
But maybe it's a good thing you've included this after all. I have no idea whence came the PRINT and NEWLINE - what language it is, or what it's instructing. Some kind of cgi perhaps? Anyways, surely, lines like this below must generate an error or "not what's intended"...
PRINT " document.writeln(' <PARAM NAME='SRC' VALUE='/ns-icons/'+MovieName+''>');" That translates to an output of:
document.writeln(' <PARAM NAME='SRC' VALUE='/ns-icons/'+MovieName+''>'); ..which is, quotewise, up the Creek without a paddle.