Important site message is displayed here.
Updated: January 15, 2009.
This script uses jQuery and Thickbox to present a message in a modal window on the first visit during the browser session. It does the following:
- creates two cookie functions (create and read)
- creates a function to show the popup
- looks for a cookie called
mypopup - if it’s absent:
- shows a modal window
- sets a cookie called
mypopup
Code
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
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(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function showModal() {
tb_show('Important message','#TB_inline?height=300&width=450&inlineId=promo',false);
}
var visited = readCookie('mypopup');
if (!visited) {
$(document).ready(function(){
showModal();
createCookie('mypopup','no',0);
});
}
Sources:
createCookie()andreadCookie()from “Cookies,” by Peter-Paul Koch- jQuery with Thickbox