Web Hosting Talk







View Full Version : Counting popups


viol
05-04-2002, 03:52 PM
Hi,
When a visitor click a picture in my site, a window pops up with a bigger version of that picture. This popped-up window is created using javascript, the .htm file doesn't really exist in the server at the moment the picture is clicked. How can I make it count for the statistics because the way it is now, I can click the pictures as many times as I want and the stats doesn't show these page views. Is there a solution using javascript?
Please, I don't use PHP, cgi, etc, just html and javascript, my host doesnt support these features and also I dont know how to use them, even if the host supprted. Thanks.

vito
05-04-2002, 04:42 PM
I'm not 100% sure, but I think the reason it's not showing up as a pageview is that you're linking to an image rather than a web page. Try creating a page that contains just the larger image and link to it as follows:

In your head section, put

-----------------------------------------------------------
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=200,left = 210,top = 160');");
}
// End -->
</script>
--------------------------------------------------------------

Where you have the thumbnail img in the <body>, put

------------------------------------------------------------
<a href="javascript:popUp('http://www.yourdomain.com/path/to/larger/image.html')"><img src="your_thumbnail_img"></a>
------------------------------------------------------------

Replace all the items I made bold in the script to suit your specific application.

I'm pretty sure this will end up showing results in your stats.

Good luck.
Vito

viol
05-04-2002, 06:10 PM
Thanks for the answer but you are opening an already existent page, using javascript. I use javascript to create and write the page dinamically, so I can re-use it to open the same page with different images. Here is the code I'm using:

function popItUp(pFile,pLegend) {
popUpWin = window.open('','popJWin','resizable=yes,scrollbars=no,width=535,height=420');
avHTM = '<html><head><title>Screenshot - MOHAA</title>';
avHTM += '<link rel="stylesheet" type="text/css" href="mohaa.css">';
avHTM += '</head>';
avHTM += '<body>';
avHTM += '<div align="center">';
avHTM += ' <center>';
avHTM += ' <table border="3" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="500">';
avHTM += ' <tr>';
avHTM += ' <td width="100%"><img border="0" src="' + pFile + '" width="500" height="375"></td>';
avHTM += ' </tr>';
avHTM += ' </table>';
avHTM += ' </center>';
avHTM += ' <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="500">';
avHTM += ' <tr>';
avHTM += ' <td width="100%">' + pLegend + '</td>';
avHTM += ' </tr>';
avHTM += ' </table>';
avHTM += '</div>';
avHTM += '</body>';
avHTM += '</html>';
window.popUpWin.document.write(avHTM);
window.popUpWin.document.close();
window.popUpWin.focus(); }

When I want to call popItUp() I pass two parameters, the name of the image file I want to show, like An_image.jpg, and a legend that will appear below the image. The name of the file and the legend are different for each thumbnail.

Is there a way to make this dinamically created page show in the stats? Thanks again.

vito
05-04-2002, 06:48 PM
Sorry, my knowledge of JS is limited. Can't help you... :(

Vito

xerocity.com
05-04-2002, 06:55 PM
While reading your post a couple of things came to mind:

1. Why do you need to have the impressions logged? If it is just for you can't you just add a counter?

2. So far in my experience, I do not think that you can do what you want to with javascript. I think you should contact your host and see if they support perl. I think that perl would be perfectly suited for this job and I could probably thow together a script in about 15 minutes and probably less than 30 line lines of code to get this job done. In my experience, most servers will recognize the results of a perl script as a page view.

If your host supports perl and you want me to throw together a script let me know.

Joel Strellner

Speakerguy
05-04-2002, 09:02 PM
Forget perl, do it in PHP =D

I know for a fact you cant do that in javascript, however, I can do it in about 30 lines of PHP code...

xerocity.com
05-04-2002, 09:32 PM
PHP, Perl, whatever...

Per Speakerguy I am going to go with my instinct that you just can't do it.

Of course you can do it in PHP also, I just prefer Perl. :D

Joel Strellner

viol
05-04-2002, 10:00 PM
My current package at my current host (Y!Geo, don't flame, please) doesn't accept Perl of Php or any similar language.
I'm thinking about moving to AlwaysWebHosting.
Thank you all for the replies.

xerocity.com
05-04-2002, 10:10 PM
If you switch hosts to one that supports perl, the offer is still on the table for the script just let me know.

Speakerguy
05-05-2002, 04:10 AM
Originally posted by xerocity.com
PHP, Perl, whatever...

Per Speakerguy I am going to go with my instinct that you just can't do it.

Of course you can do it in PHP also, I just prefer Perl. :D

Joel Strellner


*laugh*

I didnt say perl doesnt own...cuz it does

php just ownz0rz m0rez0rz =)

viol
05-07-2002, 01:07 AM
Hi,
I'm in the process of changing my web host so, if someone (xerocity.com) can send me a script for counting popups, as told before, I'd be glad to have it.
I know nothing about perl, php, cgi, etc, but I'll try to figure out how it works.
TIA

xerocity.com
05-07-2002, 01:22 AM
viol,

I sent you an email, please respond with the information requested.

I should be able to throw something together.

davidn
05-07-2002, 01:37 AM
I'll agree with most people here that this is something best suited for perl or php. I'll disagree with the "it can't be done" with javascript parts however.

Here's how.
create an html page, call it bigpicture.html (or whatever you want). In the page(s) linking to the big pictures, instead of popItUp function writing the whole page, it just pops up "bigpicture.html?picname". bigpicture.html will have all the html you were generating. It will extract picname from the url of the page and use that in generating the img tag. The img tag will be the only part of the page that needs to be written with document.write().
(That should work unless whatever is counting pages strips the query parts of urls out for stats)

But if you're switching hosting providers anyway, doing this server-side (php, perl, etc) is better.
In such a case, you could have a similar situation, with bigpicture.php?img=picname, and it would generate the img tag server-side.

viol
05-07-2002, 07:01 AM
Hi Joel, thanks for the reply. I have already answered to your email.
Hi David, I have had the idea of having an html page already existent and, when opening it, to write just the information that changes, i.e., the file name and the legend, but I completely gave up the idea because I thought it was impossible to pass parameters to an existent html page using javascript.
I didn't know you can use "bigpicture.html?picname" to pass a parameter. Can you please give a sample on how to do this? Where and how do I use this in the javascript code? TIA.

davidn
05-07-2002, 02:02 PM
Here's a live demo:

http://borg.cs.dal.ca/~nordlund/bigpicture/

You can view source on those pages to see how it's done.

Just a reminder, page counting won't work as you want it to if whatever software your host uses to count hits is factoring out query strings.

viol
05-07-2002, 07:24 PM
Thank you David, for the trouble in helping me out.
I liked your picture! You must be irresistible to the women. :-)
Seriously speaking, I'm going to test the code in my new host. I hope it works there. Greetings from Brazil.