Forum Moderators: open

Message Too Old, No Replies

Random pop up

         

Dexie

2:06 pm on Jan 30, 2005 (gmt 0)

10+ Year Member



Hi all,

Can anyone please let me know the exact change to the code below, to make it appear every 1 in 10 visits please.

Sev.

<script Language="JavaScript">
<!--

sondage();

function sondage(){
var nbFoisNum = 1;
var surNum = 10;
var rndNum;
rndNum = Math.floor(Math.random()*surNum);
if ( rndNum <= nbFoisNum ){
//Local Variable Decleration
OpenPopup();
}
}

function OpenPopup() {
openpopup = window.open("U R L à insérer ","popupwin","width=400,height=435,left=0,top=10,resizable=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no");
}

// -->
</SCRIPT>

mcibor

11:00 pm on Jan 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're using function Math.random, which as the name says is completely random. It means that the probability of page showing is as 1:10, that is not the same as showing popup every ten visits.

First appearing question is: does the popup need to come up every 10 visits of one and the same visitor, or every 10 visits, no matter who that is?

If it's 10 for one visitor then the answer lays in storing the visit info in cookie. If it's for all then you need some onserver script language, eg. php, or cgi to store the info in the file, or database.

However to say the truth I would go on with the function you wrote above, because it works quite good, and saves really a lot of effort.

Best wishes!
Michal Cibor

Dexie

8:22 am on Jan 31, 2005 (gmt 0)

10+ Year Member



Hi Michael,

It's meant to be for every 10 visits, no matter who that is, but have no experience with the cgi etc that you mentioned ;-(

Sev.

Bernard Marx

8:59 am on Jan 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Although CGI is better because it works around browsers that have cookies disabled, using cookies is perhaps easier, and may be the only option you have available.

This script does the basics for you.

[cookiecentral.com...]

Just take the numbers and use the modulus operator.

Dexie

10:00 am on Jan 31, 2005 (gmt 0)

10+ Year Member



Many thanks Bernard, much appreciated, just one thing, if you were me, would you go the cgi route please? Anyone know the rough percentages for peeps who surf with cookies disabled?

Sev.

mcibor

9:36 pm on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As I remember around 5% of peps has their cookies disabled. I would go straight for cgi, or PHP. To get the script in PHP just ask in PHP forum: www.webmasterworld.com/forum88

Best regards
Michal Cibor

PS. But be aware, that PHP requires being installed on the server to work.

Bernard Marx

9:48 pm on Feb 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you were me, would you go the cgi route please?

If I were you, I'd know your reasons and priorities, so that's a tough one.

If I were me, however, I would use the cookie route. I'd put up with the fact that it didn't work with that 5%, but maybe have a default mechanism that launches a popup at random with 10% probability when cookies are disabled.

The trouble with any CGI approach is that you can only count visits in general, not visits per individual.
- That is unless you are keeping a database of IP addresses/visits, which itself is made unreliable by network complexities like PAT and DHCP anyway (...probably!).

Dexie

9:14 am on Feb 2, 2005 (gmt 0)

10+ Year Member



Many thanks to all.

"The trouble with any CGI approach is that you can only count visits in general, not visits per individual."

As mentioned, I would want it to count general visits, not individuals, so I assume that in this case cgi would be good?

Many thanks for the link Michal, I'll take a look there as well.

Sev.