View Full Version : Random but only once
Dark Soul
04-16-2003, 11:34 PM
I've used javascript to open a random link in a popunder window every 5 minutes, but i dont know how to make it only show each link once per day.
Also is there a way I can make all links after the first open in the same popunder window??
Any help will be appreciated
Thanx
Philip M
04-17-2003, 06:57 AM
Unless you post your code or a reference it is not possible to advise you.
However, pop-under ads are guaranteed to motivate your visitors to avoid coming to your site again. Ugh!
Dark Soul
04-17-2003, 12:14 PM
I'm trying to set up a link exchange so hopefully they will come back. This is the code I am using:
<HTML>
<head>
<title> Assassins Guild Thugbuilder</title>
</head>
<BODY BGCOLOR = "BLACK">
<font color= "#FFFFFF">
<center> <h1> Welcome To The Thugbuilder </h1> </center>
<br>
<br>
<br>
<br>
<script>
//specify URLs to randomly select from and pop-under
var popunder=new Array()
popunder[0]="http://www.***********/page.php?x=471756"
popunder[1]="http://www.***********/page.php?x=558556"
popunder[2]="http://www.***********/page.php?x=787424"
var winfeatures="width=800,height=510,scrollbars=1,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0"
var once_per_session=0
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function loadornot(){
if (get_cookie('popunder')==''){
loadpopunder()
document.cookie="popunder=yes"
}
}
function loadpopunder(){
win2=window.open(popunder[Math.floor(Math.random()*(popunder.length))],"",winfeatures)
win2.blur()
window.focus()
}
if (once_per_session==0)
loadpopunder()
else
loadornot()
</script>
</head>
<body>
<noscript>
</noscript>
<center>
<script language="JavaScript">
<!--
document.writeln("<form name='my_form' action=''><table border='0' bordercolor='#00FFFF' bgcolor='#000000' cellpadding='5' cellspacing='0' width='200'><tr><td><center><font size='1' face='verdana'><input type='text' name='my_text' size='35'></font><br><font size='1' face='verdana' color='BLACK'><font color='#228B22 '></font></a></font></center></tr></td></table></form>");
var the_minutes = [ " 4", " 3", " 2", " 1", " 0" ] ;// ** add/remove quoted numbers in this line to increase/decrease page reload time - currently set to begin at 5 minutes 01 seconds
var the_seconds = [ "59", "58", "57", "56", "55", "54", "53", "52", "51", "50", "49", "48", "47", "46", "45", "44", "43", "42", "41", "40", "39", "38", "37", "36", "35", "34", "33", "32", "31", "30", "29", "28", "27", "26", "25", "24", "23", "22", "21", "20", "19", "18", "17", "16", "15", "14", "13", "12", "11", "10", "09", "08", "07", "06", "05", "04", "03", "02", "01", "00", "00" ];
var index = 0;
var a = 0;
var my_timer;
function countDown(){
if (index <= the_seconds.length){window.document.my_form.my_text.value = " Next Outwar Link in" + the_minutes[a] + ":" + the_seconds[index] + " Minutes"; index++;};
if (index == the_seconds.length){a++; index = "0";};
if (a == the_minutes.length){window.location.reload()};
my_timer = setTimeout('countDown();', 1000)};
countDown();
//-->
</script>
</HTML>
david7777
04-17-2003, 12:46 PM
First of all - to make the link open in the same window every time, you need to declare the variable "win2" as a global variable. So you need to put "var win2;" ouside of the functions.
You are using cookies already, so why not write to the cookie ever time you open a new random link? So you will randomly choose a link, then check the cookie to see if it has already been displayed, if not, display it, and write to the cookie that it has now been displayed. If the link has already been displayed, then choose a nother random link.
Just make sure to put in your code that if all the links have been displayed, and are written in the cookie, then you must clear the list of random links in the cookie and start again. if you dont do this, then your script could go into an infinite loop and mess things up :)
Dark Soul
04-17-2003, 01:23 PM
Thanx for the help. The only problem I have is I'm new to javascript so could you tell me the coding I will need or where I can find it
Thanx again
david7777
04-17-2003, 01:43 PM
Ill see what i can do, but first of all: Do you want the textbox countdown there or not? What EXACTLY do you want the script to do?
Dark Soul
04-17-2003, 01:51 PM
The script works how I want it (it shows a countdown starting at 5 minutes, when it reaches 0 it opens a random link and starts again). I just wanna add something to the code so that it doesn't repeat any of the same links that day. Also I added "var win2;" to my code but it still opens each link in a new window
This is where I added it:
//specify URLs to randomly select from and pop-under
var popunder=new Array()
popunder[0]="http://www.***********/page.php?x=471756"
popunder[1]="http://www.***********/page.php?x=558556"
popunder[2]="http://www.***********/page.php?x=787424"
var win2;
var winfeatures="width=800,height=510,scrollbars=1,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0"
var once_per_session=0
Have I done something wrong??
david7777
04-17-2003, 02:08 PM
I got the same problem when testing your code... Ill have a closer look at it and get back to you with the fixed code...
Dark Soul
04-18-2003, 01:36 AM
thanx
david7777
04-22-2003, 04:37 PM
The easter weekend got a bit hectic - sorry for taking so long...
Im having some problems with the code, but ill still get it to you... here is the current code, but the once-a-day thing doesnt work yet...
And its really messy, but ill fix that up...
<HTML>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function setCookie(name, value, expires) {
var curCookie = name + "=" + escape(value) +
((expires) ? "; expires=" + expires.toGMTString() : "");
document.cookie += curCookie;
}
// -->
</SCRIPT>
<title> Assassins Guild Thugbuilder</title>
</head>
<BODY BGCOLOR = "BLACK">
<font color= "#FFFFFF">
<center> <h1> Welcome To The Thugbuilder </h1> </center>
<br>
<br>
<br>
<br>
<script>
//specify URLs to randomly select from and pop-under
var popunder=new Array()
popunder[0]="about:0"
popunder[1]="about:1"
popunder[2]="about:2"
popunder[3]="about:3"
popunder[4]="about:4"
popunder[5]="about:5"
popunder[6]="about:6"
popunder[7]="about:7"
popunder[8]="about:8"
popunder[9]="about:9"
var popup = ""; //Debug
var links="";
var winfeatures=" width=800,height=510,scrollbars=1,resizable=0,tool bar=0,location=0,menubar=0,status=0,directories=0"
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function set_cookie(url, val){
date=new Date();
date.getDate();
//date=date.toString();
setCookie(url, val, date)
popup+=" ; "+url+":"+val+" ;"; //Debug
alert(popup); //Debug
}
function is_used(url){
ret = true;
if (get_cookie(url)!='yes'){
ret = false;
}else{
all_used = true;
for(i=0;i<popunder.length;i++){
if (get_cookie(i)!='yes'){
all_used = false;
}
}
if(all_used){
for(i=0;i<popunder.length;i++){
set_cookie(i,"no");
}
ret = false;
}else{
ret = true;
}
}
return ret;
}
function loadpopunder(){
var url;
var done = false;
while(done==false){
url=Math.floor(Math.random()*(popunder.length));
if(links.indexOf(":" + url + ":") != -1){
//continue;
alert(url + " continue!");
}
if (!is_used(url)){
win2=window.open(popunder[url],"win2",winfeatures);
win2.blur();
window.focus();
set_cookie(url,"yes");
done= true;
}else{
links += ":" + url + ":";
}
}
}
</script>
</head>
<body>
<center>
<script language="JavaScript">
<!--
document.writeln("<form name='my_form' action=''>_
<table border='0' bordercolor='#00FFFF' bgcolor='#000000' _
cellpadding='5' cellspacing='0' _
width='200'><tr><td><center><font size='1' _
face='verdana'><input type='text' name='my_text' _
size='35'></font><br><font size='1' face='verdana' _
color='BLACK'><font _
color='#228B22 '></font></a></font></center></tr></td>_
</table></form>");
var the_minutes;
var the_seconds;
var index;
var a;
var my_timer;
function reset(){
the_minutes = [ " 0" ] ;
the_seconds = [ "03", "02", "01", "00", "00" ];
index = 0;
a = 0;
}
function countDown(){
if (index <= the_seconds.length){
window.document.my_form.my_text.value = " Next Outwar Link in" + the_minutes[a] + ":" + the_seconds[index] + " Minutes";
index++;
}
if (index == the_seconds.length){
a++;
index = "0";
}
if (a == the_minutes.length){
reset();
loadpopunder();
}
my_timer = setTimeout('countDown();', 1000)
}
reset();
countDown();
//-->
</script>
</HTML>
Dark Soul
04-22-2003, 04:58 PM
im gonna try implementing now
thanx again
david7777
04-23-2003, 12:24 PM
Ok - this seems to work - i havent checked if the expiry date works though...
I added in some css style to your text box for you to play around with...
hope this helps!
<HTML>
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
var popunder=new Array()
var the_minutes, the_seconds, index, a, my_timer, winfeatures;
function init(){
//specify URLs to randomly select from and pop-under
popunder[0]="about:0"
popunder[1]="about:1"
popunder[2]="about:2"
popunder[3]="about:3"
popunder[4]="about:4"
popunder[5]="about:5"
popunder[6]="about:6"
popunder[7]="about:7"
popunder[8]="about:8"
popunder[9]="about:9"
// Set the window properties
winfeatures=" width=800,height=510,scrollbars=1,resizable=0,tool bar=0,location=0,menubar=0,status=0,directories=0"
reset_counter();
countDown();
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { // if cookie exists
offset += search.length
// set index of beginning of value
end = document.cookie.indexOf(";", offset);
// set index of end of cookie value
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}
function set_cookie(url, val){
var date = new Date();
var curCookie = url + "=" + escape(val);
document.cookie = curCookie;
document.cookie = "expires=" + date.toGMTString();
}
function is_used(url){
ret = true;
if (get_cookie(url)!='yes'){
ret = false;
}else{
all_used = true;
for(i=0;i<popunder.length;i++){
if (get_cookie(i)!='yes'){
all_used = false;
}
}
if(all_used){
for(i=0;i<popunder.length;i++){
set_cookie(i,"no");
}
ret = false;
}else{
ret = true;
}
}
return ret;
}
function loadpopunder(){
var url;
var done = false;
while(done==false){
url=Math.floor(Math.random()*(popunder.length));
if (!is_used(url)){
win2=window.open(popunder[url],"win2",winfeatures);
win2.blur();
window.focus();
set_cookie(url,"yes");
done= true;
}
}
}
function reset_counter(){
the_minutes = [ " 4", " 3", " 2", " 1", " 0" ] ;// ** add/remove quoted numbers in this line to increase/decrease page reload time - currently set to begin at 5 minutes 01 seconds
the_seconds = [ "59", "58", "57", "56", "55", "54", "53", "52", "51", "50", "49", "48", "47", "46", "45", "44", "43", "42", "41", "40", "39", "38", "37", "36", "35", "34", "33", "32", "31", "30", "29", "28", "27", "26", "25", "24", "23", "22", "21", "20", "19", "18", "17", "16", "15", "14", "13", "12", "11", "10", "09", "08", "07", "06", "05", "04", "03", "02", "01", "00", "00" ];
index = 0;
a = 0;
}
function countDown(){
if (index <= the_seconds.length){
window.document.my_form.my_text.value = " Next Outwar Link in" + the_minutes[a] + ":" + the_seconds[index] + " Minutes";
index++;
}
if (index == the_seconds.length){
a++;
index = "0";
}
if (a == the_minutes.length){
reset_counter();
loadpopunder();
}
my_timer = setTimeout('countDown();', 1000)
}
// -->
</SCRIPT>
<title> Assassins Guild Thugbuilder</title>
</head>
<BODY BGCOLOR = "BLACK">
<font color= "#FFFFFF"><center><h1> Welcome To The Thugbuilder </h1></center>
<br>
<br>
<br>
<br>
<center>
<form name="my_form" action="">
<table border="0" bordercolor="#00FFFF" bgcolor="#000000" cellpadding="5" cellspacing="0" width="200">
<tr>
<td>
<input style="font-size:xx-small; font-weight : bold; font-family : Verdana, Geneva, Arial, Helvetica, sans-serif; border : 1px inset lightGray; color : #2f2f2f;" type="text" name="my_text" size="35">
</td>
</tr>
</table>
</form>
<script language="JavaScript">
<!--
init();
//-->
</script>
</body>
</HTML>
:cool:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.