Webmaster Forum

Sponsored Reviews   Keyword Research Tool   V7N Directory
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Coding Forum Problems with your code? Let's hear about it.

Reply
 
LinkBack Thread Tools Display Modes
Old 09-29-2007, 01:28 AM   #1 (permalink)
Contributing Member
 
Join Date: 05-07-06
Posts: 89
iTrader: 0 / 0%
Latest Blog:
None

poseidon is liked by many
How to set cookie to the visitor so pop only gets shown once ?

I am working on a popup script which gets shown when the user leaves the page. The problem is, the user keep on getting shown that page whenever he leaves page Everytime which I dont' want.

I just want the pop up to be shown to the first time visitor only. That's it. This can be easily done with PHP but I am just wondering what's the best way of doing it ? Is putting such cookie function on footer file a good idea, since it will called everytime when the page gets load, increasing the loadtime of the page ?

Cheers
__________________
The Ultimate Link and Traffic Building Guide
nBridges Media - Your SEO and SEM Partner
Contact US to Know more about My Work and for SEO inquiries
poseidon is offline  
Add Post to del.icio.us
Reply With Quote
Sponsored Links
SEO Hosting by HostGator  Advertise Here  Buy Blog Links
Old 09-29-2007, 06:48 PM   #2 (permalink)
v7n Mentor
 
Costin Trifan's Avatar
 
Join Date: 04-13-07
Location: Romania (atm)
Posts: 2,846
iTrader: 0 / 0%
Costin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web proCostin Trifan is a highly respected web pro
Smile Yay! Cookies! Yum!

I knew I had a script for this!

Here it is:

The javascript file:
Code:
var expDays = 1; // number of days the cookie should last var page = "http://www.google.com"; // URL to the pop-up var windowprops = "width=600,height=300,location=no,toolbar=no,menubar=no,scrollbars=no,resizable=no"; // popup window features 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.onunload = checkCount;
the HTML file:
Code:
<head> <title>Test Page</title> <script src="cookie_test.js" type="text/javascript"></script> </head> <body> </body>
Hope you like it!
Costin Trifan is offline  
Add Post to del.icio.us
Reply With Quote
Go Back   Webmaster Forum > Web Development > Web Design Lobby > Coding Forum

Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Images shown on web results page SVB Google Forum 2 02-04-2005 11:19 AM
Put a cookie on my introduction stephen's face Coding Forum 7 07-14-2004 11:37 AM
Cookie SN3 Coding Forum 58 12-14-2003 05:49 AM


Sponsor Links
Get exposure! Get exposure! Find Scripts Web Hosting Directory Get exposure! SEO Blog


All times are GMT -7. The time now is 10:24 AM.
© Copyright 2008 V7 Inc


Search Engine Optimization by vBSEO 3.1.0 ©2007, Crawlability, Inc.