我有一個函數在頁面加載時向訪問者顯示一個隱藏的div特別優惠,然後設置一個cookie,以便它僅在用戶第一次加載頁面時顯示。我希望能夠在div顯示之前設置所需的訪問次數,因此我只能在第三頁加載時顯示隱藏的div。但我一直無法弄清楚如何做到這一點。任何人都可以將我指向正確的方向嗎?在第三頁顯示隱藏的div加載
function CreatePopup(url, height, duration, description, lifetime) {
// Exit if the current browser has already received the popup, or
// the browser is not supported (IE6).
if (HasAlreadyReceivedPopup(description) || IsUnsupportedUserAgent())
return;
$.get(url, function(data) {
/*var popup = $("<div>" + data + "</div>")
.attr({ "id": "sliding_popup" })
.css({"bottom": -1 * height})
.height(height)
.hide()
.appendTo("body");*/
popup = $("<div>" + data + "</div>")
.attr({ "id": "sliding_popup" })
.hide()
.appendTo("body");
ShowPopup(description, lifetime, popup, duration);
});
}
function ShowPopup(description, lifetime, popup, duration)
{
popup.show().animate({ top: 100 }, duration);
ReceivedPopup(description, lifetime);
}
function HasAlreadyReceivedPopup(description) {
return document.cookie.indexOf(description) > -1;
}
function ReceivedPopup(description, lifetime) {
var date = new Date();
date.setDate(date.getDate() + lifetime);
document.cookie = description + "=true;expires=" + date.toUTCString() + ";path=/";
}
function IsUnsupportedUserAgent() {
return (!window.XMLHttpRequest);
}
function DestroyPopup(duration) {
$("#sliding_popup").animate({ top: $("#sliding_popup").height() * -1 }, duration, function() { $("#sliding_popup").remove(); })
}
function SecondVisit(description)
{
if (HasAlreadyReceivedPopup(description)) {
return true;
}
else
{
return false;
}
}
的函數被調用的包括像這樣:
的函數被調用,像這樣
$(document).ready(function() {
// This check is used by the demo to allow you to remove the cookie. Do not use in production code.
if (HasAlreadyReceivedPopup("promo"))
$("#note").show().click(function() {
document.cookie = name + "promo=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT"; location.reload(true);
});
CreatePopup("page.html", 300, 1500, "promo", 5);
});