Pop up codziennie inny

czwartek, 11 marzec 04, 10:20

Co myślisz o skrypcie, który pozwala ustawić cookies w taki sposób, że wchodząc ponownie na witrynę w odstępie kilku dni wyświetlane jest ci inny pop-up?

Dariusz Mlynarski napisał/a na Merytorium.pl dnia 2004-03-11 18:06:45:

Znalazłem ciekawy skrypt, który daje możliwość ustawienia cookies w taki sposób, że np. wchodząc ponownie na witrynę w odstępie kilku dni za każdym razem wyswetla inny pop-up. A wchodząc drugi raz tego samego dnia, już nie zobaczy żadnego pop-upa. Podoba mi się takie rozwiązanie. Dla zainteresowanych- voila

// Popup routines

// Define array (url, x, y, blockingcookie,scrollbars,name)
// tutaj wpisujesz adresy kolejnych popupow
var url=new Array(4);
url[0]=['http://www.neovita.pl/_popups/pop_load.htm','450','400','','no','subscribe';
url[1]=['http://www.neovita.pl/_popups/pop_again.htm','450','400','','no','czy_subscribed';

var exit=true;
var win=null;
var days=1; // Number of days before next popup



// Use this routine on the onclick event of any links you DON'T want popups on
function setExitFalse(){
exit=false;
}


function showPopup(popupName){
// Get the optional name parameter


if(typeof(popupName) == "undefined") {
// If it is not defined, use the next rotated popup
pickNextRotation();

} else {
var popped;
// If it is defined, does that actual popup exist?
for (n=0;n<url.length;n++) {
// alert(url[n][5] + ' ' + popupName);
if (url[n][5] == '') {
// It doesn't exist, use a rotation popup
pickNextRotation('nocheck');
popped = true;
} else if (url[n][5] == popupName) {
// It does exist, use that popup
NewWindow(url[n][0],'popup',url[n][1],url[n][2],'custom','front',url[n][4],'nocheck');
popped = true;
break;
}
}
if (!popped) {
pickNextRotation('nocheck');
}
}
}


function pickNextRotation(checkcookie) {
// Open window if cookie not found
// alert('CFC: ' + checkcookie);
var i=0; // Default ID

// Get the last ID used
var allcookies=documentXcookie;
var pos=allcookies.indexOf('popup=');
if(pos!=-1){
var start=pos+6;
var end=allcookies.indexOf(';',start);
if(end==-1) {
end=allcookies.length;
}
var i=allcookies.substring(start,end);

if (i==url.length-1) {
i=0;
} else {
i++;
}
}
//alert("Start with "+ i);

if (i > url.length) {
i = 0;
}



// Now loop until you find one that is not blocked
for (j=i; j < url.length; j++) {
var allowed=1;
//alert ("Checking url " + j);
if (url[j][3] != "") {
// There is a blocking cookie - find the value
//alert('Looking for cookie ' + url[j][3]);
var allcookies=documentXcookie;
//alert('allcookies='+ allcookies);
var pos=allcookies.indexOf(url[j][3] + '=');
if(pos!=-1){
//alert('Found subscribed at ' + pos);
var start=pos + url[j][3].length + 1;
var end=allcookies.indexOf(';',start);
if(end==-1) {
end=allcookies.length;
}
var cookieval=allcookies.substring(start,end);
allowed = 0;
} else {
//alert ('Subscribed not found');
}

}

if (allowed==1) {
//alert("allowed");
break;
} else {
//alert ("not allowed:" + allowed);
}

} // Continue loop
//alert("Ended with " + j);

NewWindow(url[j][0],'popup',url[j][1],url[j][2],'custom','front',url[j][4],checkcookie);
setCookie(i);
}

function NewWindow(mypage,myname,w,h,pos,infocus,scrollbars,checkforcookie){
// alert (checkforcookie);
if (typeof(checkforcookie) == "undefined") {
if(GetCookie("sid") == "999"){
return;
}
}
documentXcookie="sid=999; Path=/; Expires= " + getFuture(days);
if(pos=="random"){
myleft=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
mytop=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
}
if(pos=="center"){
myleft=(screen.width)?(screen.width-w)/2:100;
mytop=(screen.height)?(screen.height-h)/2:100;
} else if((pos!='center' && pos!="random") || pos==null){
myleft=0;
mytop=20;
}
settings="width=" + w + ",height=" + h + ",top=" + mytop + ",left=" + myleft + ",scrollbars=" + scrollbars + ",location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes";

win=window.open(mypage,myname,settings);
win.focus();
}

function getFuture(f){
var d = new Date();
d.setTime(d.getTime() + (86400000 * f)); // Milliseconds!
return d;
}

function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = documentXcookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (documentXcookie.substring(i, j) == arg) {
return getCookieval_(j);
}
i = documentXcookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}


function setCookie(i){
var nextyear=new Date();
nextyear.setFullYear(nextyear.getFullYear()+1);
documentXcookie='popup='+i+';path=/;expires='+nextyear.toGMTString();
}

function getCookieval_(offset) {
var endstr = documentXcookie.indexOf (";", offset);
if (endstr == -1)
endstr = documentXcookie.length;
return unescape(documentXcookie.substring(offset, endstr));
}

Czytaj na Forum Merytorium.pl