JavaScript, VBScript, cycling, and counters

Results 1 to 2 of 2

Thread: JavaScript, VBScript, cycling, and counters

  1. #1
    Join Date
    Dec 1969

    Default JavaScript, VBScript, cycling, and counters

    Don&#039t worry if you don&#039t feel like gathering up snippets. I&#039m hoping to at least get some direction from someone. I was raised on VBScript and am now faced with using JavaScript to cycle ads. I have the code, and it goes as follows:<BR><BR>- - - - - - - - - - - - - - <BR>&#060;SCRIPT LANGUAGE=JAVASCRIPT&#062;<BR>&#060;!-- <BR>var adImages = new Array("banner1.gif", "banner2.gif", "banner3.gif")<BR>var thisAd = 0<BR>function cycle() {<BR> if (document.images) {<BR> if (document.adBanner.complete) {<BR> thisAd++<BR> if (thisAd == 3) {<BR> thisAd = 0<BR> }<BR> document.adBanner.src=adImages[thisAd]<BR> }<BR> setTimeout("cycle()", 3 * 1000)<BR>}<BR>}<BR>// -- &#062;<BR>&#060;/SCRIPT&#062;<BR><BR>&#060;IMG SRC="banner1.gif" WIDTH="468" HEIGHT="60" NAME="adBanner"&#062;<BR>- - - - - - - - - - - - - - <BR>This works. These three ads cycle fine. <BR><BR>The tricky part is that I want to record impressions for each ad as it gets cycled. If I can figure out how to capture the name of the current ad being cycled, I know how to handle the counter from there.<BR><BR>Will JavaScript allow me to extract the name of each ad as it cycles through? I&#039m not savvy enough to even know what to say to get it. I don&#039t care about what order ads appear, too, so would it be a good idea to randomly select from my list of ads before this code and only plug one name at a time into the array? I could then be sure which ad is currently showing. But then the problem is that only the code above is cycling every 3 seconds. The VBScript above it will load once and get stripped from the page, right?<BR><BR>I am willing to revamp my whole approach if someone could advise.<BR><BR>Summary of my intentions: Cycle ads on a page at set intervals and record an impression for each ad when it show up.<BR><BR>Thanks all!

  2. #2
    Join Date
    Dec 1969

    Default RE: JavaScript, VBScript, cycling, and counters

    You wrote:<BR>"The VBScript above it will load once and get stripped from the page, right?"<BR><BR>Huh? What "VBScript above"? You show only the client side JavaScript.<BR><BR>********************<BR><BR>Lot s of ways to do this. But might be easier to start from the "other end". How does your click-thru code work?<BR><BR>You show<BR>&nbsp;&nbsp;&nbsp;&nbsp;&#060;IMG SRC="banner1.gif" WIDTH="468" HEIGHT="60" NAME="adBanner"&#062;<BR>but you don&#039t show any "onClick" or other code that does the click-thru.<BR><BR>I might note that you already *have* the information about which ad is being displayed:<BR>&nbsp;&nbsp;&nbsp;&nbsp;currentGifFi le = adImages[thisAd];<BR><BR>And I also might note that a minor change in your code will make it easy for you to later change the number of ads you rotate through. Instead of<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (thisAd == 3) { thisAd = 0; }<BR>just do<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (thisAd &#062;= adImages.length) { thisAd = 0; }<BR><BR>Now the reset to the first banner depends on number of names in the array.<BR><BR>***************<BR><BR>Hmmm...I reread your message, and I&#039m confused. You appear to want to record the number of times each ad *appears*??? Instead of the number of click-thrus? Why? Nobody pays for per-appearance ads nowadays, do they? I thought it was all click-thru based?<BR><BR>Anyway...WHERE would you record the info? Capturing it is a piece of cake. Capturing it *in the page*, that is. But suppose the user simply goes directly to some other URL from your page. How do you then transfer the counts back to the server? *THAT* is the tricky part; probably impossible in the most general case. And another reason, I suspect, that click-thru counts are what are mostly used.<BR><BR>I would *suggest* (but not insist) that if you *really* want to record ad appearances, then you might be better off doing it with server driven code than browser driven. But that puts a hefty load on the server, so think hard about it.<BR><BR>Sure you don&#039t want to do click-thrus instead? That is *so* much easier.<BR><BR><BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts