Forum Moderators: open

Message Too Old, No Replies

random popup

question

         

kwery

10:29 pm on Mar 14, 2004 (gmt 0)

10+ Year Member



hey! I have this function that is suppose to call a popup once in 10 visit on a page. It looks like it's not working. Can someone take a look at it? here's the code;

sondage();

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

thank you
kw

Rambo Tribble

1:46 am on Mar 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is not a complete code listing. Sondage should be called by something, though I suppose you could get away with just having it run on load by being executed in line, however OpenPopup() must be defined. Where's the code defining OpenPopup()?

kwery

11:11 pm on Mar 15, 2004 (gmt 0)

10+ Year Member



I didn't include the part of my code that define the popup cause i thaught it was not necessary. here's the code :

<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>

Purple Martin

6:04 am on Mar 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It works, but it opens the popup if rndNum is 0 or 1, so you'll get the popup 1 in 5 loads on average. To make it work 1 in 10 times, change the if statement.