View Full Version : Display hidden layer only once per visit

06-10-2007, 03:15 PM
I want to call a pop up registration form from my home page. However, I only want it to be called just once so that I don't annoy visitors. How do I best achieve this?
I want to use a hidden layer for the pop up so my question is can I use DHTML in the middle of a conditional javascript if statement. i.e. before the end of the curly brackets so that it is a result of the conditional statement? Do I have to enclose the DHTML in anyway; as you can see I am pretty new to javascript/DHTML?
I have tried to use cookies to flag a second visit to the home page; am I getting warm? Can anybody help me with some suggestions or point me at some code I can look at?
In anticipation of assistance

06-10-2007, 06:40 PM
Yeah, you're getting warm. Try using PHP sessions. Once the form is called the first time, create a PHP session. Then, on the index, check if that session exists. If it doesn't, meaning it's their first visit to the index page, show the popup. If it does exist, don't show the popup. If you need specific code, let me know.

06-10-2007, 08:14 PM
Without PHP you could try using cookies. Whenever a page in within your domain loads, have a pagesOpened count go up and reset a cookie with the new value. If the value is zero (when the first page loads) then the counter would increment and the pop-up could display. Then when each window onunloads decremenet the count in the cookie. I think this would work.

12-10-2007, 05:24 PM
People are always telling me that more sinple, is better, so;

why not simply initiate your popup on your index.html page, then, after a user selects another page (or whatever), always/only point them 'back' to an identical index page (index2.html), without the popup on it ..

12-10-2007, 10:45 PM
if you're leaning toward javascript, here you go:


.unviewed {

.viewed {

function setViewed() {

var date = new Date();
var expires="+date.toGMTString();
document.cookie = "seen=yes;"+expires+"; path=/";

function returncookie() {
var name = "seen";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
return null;
function checkViewed {
var viewed = returncookie();
if (viewed != null) {
document.getelementbyid('layer').class = "viewed";
} else {
document.getelementbyid('layer').class = "unviewed";

and for the body tag:

<body onLoad="checkViewed()">
and set your layer's id to "layer"

12-10-2007, 10:55 PM
for php:

function setViewed() {
setcookie("viewed", "yes", time()+99999);

if (isset($_COOKIE[viewed])) {
} else {
echo "layer code";