By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

Combining a Perl download counter script with an audio player pop-up window

P: 4
I'd be most grateful if someone would help me. I hope I'm in the right forum (apologies if not) - I'm not sure whether my problem is CGI or Javascript related.

I found a script called BatmoAudiopop.js which opens a pop-up browser window with an audio player when a link is clicked. Basically, it sets the right mime-type depending on the operating system and audio file type, then opens a window with the audio file (passed as a parameter) in an object with a
Expand|Select|Wrap|Line Numbers
  1. param name=src
and an
Expand|Select|Wrap|Line Numbers
  1. embed
statement each referencing the audio file. The calling HTML code is
Expand|Select|Wrap|Line Numbers
  1. <a href="audiofile.mp3" target="_blank" onclick="javascript:BatmoAudioPop('description',this.href,'1'); return false"> 
(The third parameter (1) is the window number.) It works fine.

I found another server-side script called load.cgi that opens a text file, finds the passed url name of the file to be downloaded in it, updates the count associated with it (or, if not there, creates a new entry with the count set to 1) then redirects the page with
Expand|Select|Wrap|Line Numbers
  1. print: "Location: $link\n\n";
It is called with
Expand|Select|Wrap|Line Numbers
  1. <a href="cgi-bin/load.cgi?downloadfile.whatever">
An associated script, showload.cgi, gets the current count for the passed url name so that it can be displayed in the page. The load.cgi / showload.cgi combination works fine.

What I'm trying to do is to combine the two scripts (BatmoAudiopop.js and load.cgi) so that when someone clicks on 'PLAY', the count gets updated at the server and the pop-up player opens. (Note - I don't care about the 'calling' page getting its count updated at this point - just the next time it is viewed.)

If I just alter the javascript call to
Expand|Select|Wrap|Line Numbers
  1. <a href="cgi-bin/load.cgi?audiofile.mp3" target="_blank" onclick=javascript etc....
then, to my surprise, the count gets updated by 3 instead of 1 (I'm sure I also saw it get updated by 4 once, but I might have been hallucinating).

I've examined load.cgi and can't see how the search/update loop can be going wrong - I can only surmise that the script is being called three times.

I've tried altering the javascript to remove the
Expand|Select|Wrap|Line Numbers
  1. cgi-bin/load.cgi?
(displaying the result in the pop-up window to confirm my code) but, of course, this results in the script not being called at all.

I don't really understand the relationship between the href parameter and what happens with onclick.

I've spent ages searching the Internet to see if anyone else has tried to do a similar thing and to try to glean more understanding, with no luck. The cgi script runs on my ISP's server; I don't really want to set up a web server on my machine and spend hours experimenting - I want to get on with editing my audio play!

Can anyone explain why the count should be getting updated by 3? And how I can achieve the result I want? (I suppose I could just divide the count by 3 before displaying it, but that's not very elegant.)

I would have included the entire scripts but, since they are shareware, I'm not sure about the etiquette of doing that - I don't want to offend anyone.
Aug 14 '07 #1
Share this Question
Share on Google+
2 Replies


KevinADC
Expert 2.5K+
P: 4,059
No way to tell why the counter is incremented incorrectly. My guess is the script is accessed three times for some unknown reason.
Aug 15 '07 #2

P: 4
I've cheated and changed showload.cgi to divide the count by three if it's my audio file. But I'd really like to know why load.cgi is being executed three times - perhaps one of these days soon I'll install Apache and do some experimenting. Thanks for your reply though.
Aug 16 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.