If the level of support is enough for your needs, I would go with LocalStorage.
You can wrap the code inside a function. Then when the user enters your page, just check if there's a item in the storage. If not, call the function and set the item.
For experimentation, you can use a custom timestamp. Set the value of the item as the current date in milliseconds. Then you can check if it was set more than seven days ago.
Like this:
$(document).ready(function () {
if (typeof (Storage) !== "undefined") {
// get the current date
var dateSevenDaysAgo = new Date();
// decrease 7 days from the current date, so it will repesent the date 7 days ago
dateSevenDaysAgo.setDate(dateSevenDaysAgo.getDate() - 7);
// get the excperiationDate item from localStorage
var expirationDate = localStorage.getItem("expirationDate");
// check if the excperiationDate item doesn't excist
// OR if it has been set more than 7 days ago
if (!expirationDate || expirationDate < dateSevenDaysAgo.getTime()) {
// notice that getTime stores the date in milliseconds after/before January 1, 1970
localStorage.setItem("expirationDate", new Date().getTime());
showWelcomeMessage();
}
} else {
// LocalStorage is not supported in users browser
}
function showWelcomeMessage() {
setTimeout(function () {
$('.welcomemessage').slideToggle('slow');
}, 1000);
setTimeout(function () {
$('.welcomemessage').hide('slow');
}, 20000);
setTimeout(function () {
$(".td-page-wrap").animate({
marginTop: "800px"
}, 750);
}, 1000);
setTimeout(function () {
$(".td-page-wrap").animate({
marginTop: "0px"
}, 750);
}, 20000);
$('.closewelcomemessage').click(function () {
$(".welcomemessage").hide();
$(".td-page-wrap").animate({
marginTop: "0px"
}, 750);
});
}
});
You also had some extra commas after every marginTop: Xpx
. I removed those.
EDIT: Updated the answer to match the new requirements (expiration).