CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Popup window to collect reader subscriptions (http://www.codingforums.com/showthread.php?t=240899)

ruthy 10-14-2011 01:50 AM

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!!!


All times are GMT +1. The time now is 08:55 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.