View Full Version : Pop-Ups
motokouzi
04-29-2003, 03:17 PM
Hello there :)
I'm using the following code in order to have 3 URLs appearing (once at a time) when surfing in a page. What I want to do is having each of these pop-ups appearing only ONCE per 2-3 hours..
Please help me, I'm completely lost :((
Many thanks!
<script>
//specify URLs to pop-up
var popwin=new Array()
popwin[0]="popa.htm"
popwin[1]="popb.htm"
popwin[2]="popc.htm"
var winfeatures="width=290,height=290,scrollbars=0,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('popwin')==''){
loadpopwin()
document.cookie="popwin=yes"
}
}
function loadpopwin(){
window.open(popwin[Math.floor(Math.random()*(popwin.length))],"",winfeatures)
}
if (once_per_session==0)
loadpopwin()
else
loadornot()
</script>
tamienne
04-29-2003, 03:22 PM
Add an expiration to your cookie of 3 hours. Look for the cookie if it exists then don't do anything... you can set 3 different cookies so you can look for the 3 urls separately
motokouzi
04-29-2003, 03:24 PM
thanks :)
since I'm a newbie to this..can you help me a bit in implementing it??
many many many thanks!
Originally posted by tamienne
Add an expiration to your cookie of 3 hours. Look for the cookie if it exists then don't do anything... you can set 3 different cookies so you can look for the 3 urls separately
tamienne
04-29-2003, 03:45 PM
<script>
//specify URLs to pop-up
var popwin=new Array()
popwin[0]="popa.htm"
popwin[1]="popb.htm"
popwin[2]="popc.htm"
var winfeatures=" width=290,height=290,scrollbars=0,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 set_cookie(Name, Value) {
var hours = 3;
var expiration = new Date((new Date()).getTime() + hours*3600000);
var cookie = Name + "=" + Value + ";path=/;expires=" + expiration;
document.cookie = cookie;
}
function loadornot(){
if (get_cookie('popwin')==''){
loadpopupwin();
}
}
function loadpopwin(){
window.open(popwin[Math.floor(Math.random()*(popwin.length))],"",winfeatures)
set_cookie('popwin','yes');
}
if (once_per_session==0)
loadpopwin()
else
loadornot()
motokouzi
04-30-2003, 08:09 AM
Thanks tamienne :) You're an angel!
I've added the script but I'm getting an "Unterminated string constant" error..
Any ideas what this might be??
thanks thanks thanks
Originally posted by tamienne
<script>
//specify URLs to pop-up
var popwin=new Array()
popwin[0]="popa.htm"
popwin[1]="popb.htm"
popwin[2]="popc.htm"
var winfeatures=" width=290,height=290,scrollbars=0,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 set_cookie(Name, Value) {
var hours = 3;
var expiration = new Date((new Date()).getTime() + hours*3600000);
var cookie = Name + "=" + Value + ";path=/;expires=" + expiration;
document.cookie = cookie;
}
function loadornot(){
if (get_cookie('popwin')==''){
loadpopupwin();
}
}
function loadpopwin(){
window.open(popwin[Math.floor(Math.random()*(popwin.length))],"",winfeatures)
set_cookie('popwin','yes');
}
if (once_per_session==0)
loadpopwin()
else
loadornot()
motokouzi
04-30-2003, 03:45 PM
Ok, I've changed my mind..and I'm now working on this..which doesn't seem to work either :((( I'm sure my CheckCookie function has some problems..
Please help me..and many thanks in advance
<SCRIPT LANGUAGE="JavaScript">
//specify URLs to randomly select from and pop-up
var popwin=new Array()
popwin[0]="popa.htm"
popwin[1]="popb.htm"
popwin[2]="popc.htm"
//specify popwin window features
var winfeatures="width=290,height=290,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0"
CN="PopUp"
function CheckCookie()
{
if (document.cookie && document.cookie.indexOf(CN) != -1)
{
if(get_cookie(CN)==0)
{
window.open(popwin[1],"",winfeatures);
document.cookie=CN+"=1";
}
if(get_cookie(CN)==1;
{
window.open(popwin[2],"",winfeatures);
document.cookie=CN+"=2";
}
}
else
{
window.open(popwin[0],"",winfeatures);
document.cookie=CN+"=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;
}
</SCRIPT>
tamienne
04-30-2003, 04:15 PM
it looks like some of the code needs to be on the same line. For instance...
var winfeatures=" width=290,height=290,scrollbars=0,resizable=0,toolbar=0,location=0,menubar=0,status=0,directories=0"
should be one line...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.