...

View Full Version : Random number based PopUnder



Ekix
12-04-2006, 11:13 AM
Hello guys,

I'd like to know hoe to do a PopUnder window (to an URL) so, that it starts only randomly. for example every 20'th time someone loads the page.
The frequency should be changeable, so it should be based on random numbers between 1 and n, so in case a visitor "get's" random number 20 for example, he'll get's a popunder window like "www.google.com", but if the visitor get's number 1-n (not 20), no popunders appears.

Thanks/
Ekix

brandonH
12-04-2006, 11:37 AM
<script type=text/javascript>
var outof='20';
randnumber=Math.round(Math.random()*(outof-1));
randnumber++;
if(randnumber=='1'){window.open('http://www.yahoo.com');}
</script>


the above will generate a random number between 1 and 20, and if the number is 1, it'll open up a window(popup).

you'll need to decide what add to show them, and how big to make window , ect.....

Ekix
12-04-2006, 11:59 AM
Thanks for your fast reply. Just one thing, I would like the window to appear as popunder instead pf popup. Is this possible?



Thanks/
Ekix

brandonH
12-04-2006, 12:49 PM
sorry, went to go eat breakfast.

</body>
<script type=text/javascript>
var outof='20';
randnumber=Math.round(Math.random()*(outof-1));
randnumber++;
if(randnumber=='1'){
var mypopup=window.open('');
mypopup.blur();window.focus();

}
</script>


that will bring focus to the main window(putting popup under it).
the only thing is though, is some sites call focus to their window after the page is loaded, like yahoo.com . so if they call focus then the popup will come back on top.

brandonH
12-04-2006, 01:10 PM
and if you have multiple ad's that you want to be randomly displayed do as such:



<script type=text/javascript>
var outof='20'; //chance of popunder opening
var ads=new Array();
ads[0]="http://www.yahoo.com";
ads[1]="http://www.google.com";
ads[2]="http://www.codingforums.com";
ads[3]="http://www.pogo.com";
//keep adding site addresses for more ads
randAD=Math.floor(Math.random()*ads.length);
randnumber=Math.round(Math.random()*(outof-1));
randnumber++;
if(randnumber=='1'){
var mypopup=window.open(ads[randAD]);
mypopup.blur();window.focus();

}
</script>

Ekix
12-04-2006, 01:33 PM
I could not get it working for some reason, and I'd just like to open 1 PopUnder (http://www.google.com) for example. Here's how I did it:

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>PopUnder</title>
</head>
<body>
<script type="text/javascript">
var outof='20'; //chance of popunder opening
var ads=new Array();
ads[1]="http://www.yahoo.com";

//keep adding site addresses for more ads
randAD=Math.round(Math.random()*ads.length);
randnumber=Math.round(Math.random()*(outof-1));
randnumber++;
if(randnumber=='1'){
var mypopup=window.open(ads[randAD]);
mypopup.blur();window.focus();
}
</script>
<div style="text-align: center;"><big><big><big><big><big>PopUnder</big></big></big></big></big></div>
</body>
</html>

If you have time, pls. check and advice me what's the problem.

anyway "var outof='20'" is the biggest random number, and I could change it to 100 for example?
Thanks/
Erkki

brandonH
12-04-2006, 01:38 PM
well..... the problem is here:

ads[1]="http://www.yahoo.com";


in scripting everything starts counting from 0, not 1.

so you must do like so:

ads[0]="http://www.yahoo.com";

if you only want one possible ad then use this script:


script type=text/javascript>
var outof='20';
var address="http://www.google.com";
randnumber=Math.round(Math.random()*(outof-1));
randnumber++;
if(randnumber=='1'){
var mypopup=window.open(address);
mypopup.blur();window.focus();

}
</script>


and yes, you can change that number to whatever you want, as long as its a number that is.

Ekix
12-04-2006, 02:02 PM
I just can't get it working, here's the code as I used it:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>PopUnder</title>
script type=text/javascript&gt;
var outof='20';
var address="http://www.google.com";
randnumber=Math.round(Math.random()*(outof-1));
randnumber++;
if(randnumber=='1'){
var mypopup=window.open(address);
mypopup.blur();window.focus();
}
</head>
<body>
<br>
<div style="text-align: center;">PopUnder Test</div>
</body>
</html>

And here's the result's Url:

http://www.kolumbus.fi/miracle/eki/popunder.html

I'm sorry to disturb you again/
Ekix

brandonH
12-04-2006, 02:10 PM
try this:





<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>PopUnder</title>
<script type=text/javascript>
var outof='20';
var address="http://www.google.com";
randnumber=Math.round(Math.random()*(outof-1));
randnumber++;
if(randnumber=='1'){
var mypopup=window.open(address);
mypopup.blur();window.focus();
}
</script>
</head>
<body>
<br>
<div style="text-align: center;">PopUnder Test</div>
</body>
</html>

Ekix
12-04-2006, 02:37 PM
Hello again

Thanks, Now it seem's to work, exept it comes as PopUp instead of PopUnder.
Is there any way to change that, and is there any way to override the IE's PopUp Blocker, it works if it's Blocker is off, but in case it's on, does not work.

Regards/
Ekix again

brandonH
12-05-2006, 03:42 AM
if the contents of the window are a page that is not yours, you have no real control over wether bor not the window stays under the main window. sites like yahoo and google set focus to their search text boxes when the pages loads, which i believe draws focus to the window.

and sorry to say, but no there is no way to over-ride pop-up blockers. the user can turn it off. and i believe there is a way to detect if a user has their pop-up blocker on. if they do you can alert them that they need to turn it off in order to use your site. how to do that I do not know.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum