View Single Post
Old 10-14-2011, 01:50 AM   PM User | #1
ruthy
New to the CF scene

 
Join Date: Oct 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ruthy is an unknown quantity at this point
Popup window to collect reader subscriptions

Hello, I'm a newbie... Have a teensy bit of Javascript skills from school. I have two questions about a popup window I've installed on my website to collect subscriptions.

The code below is working on my website here http://ruthysrides.com.au/cycling-accessories.php, and is programmed to appear once per user every 30 days.

Questions are:

1. I want to know how I can make the popup open centred on the screen. (I've looked at a few examples of code but can't see where to insert the instruction)

2. Ideally I want to insert the popup on every page and set it to appear after the user has been browsing for 60 seconds, but I couldn't get example codes working so settled for this one.

I initially installed it on 3 different pages, but it only recognised the cookie from one page and so when the user clicks on another page with the script installed, the subscription prompt pops up again. Annoying for customers, so I've only got the script running on the one page at the moment.

<script language="javascript">

var expDays = 30; // number of days the cookie should last

var page = "http://www.ruthysrides.com.au/subscribe.php";
var windowprops = "width=340,height=300,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes";

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

function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
var count = GetCookie('count')
if(count == null) {
SetCookie('count','1')
return 1
} else {
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}

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

function checkCount() {
var count = GetCookie('count');
if (count == null) {
count=1;
SetCookie('count', count, exp);
window.open(page, "", windowprops);
} else {
count++;
SetCookie('count', count, exp);
}
}

window.onload=checkCount;
</script>

Help anyone? Big thank you in advance!!!

Last edited by ruthy; 10-14-2011 at 02:24 AM.. Reason: forgot to post code oopsy
ruthy is offline   Reply With Quote