私は現在、年齢確認が必要なウェブサイトに取り組んでいます。現在のコーディング方法では、フッターに agecheck div があり、最初のページ読み込み時に表示され、ユーザーが [はい] をクリックするまで表示されたままになります。[はい] をクリックすると、ofage Cookie が true に設定され、div が非表示になります。これに関する問題は、ユーザーが年齢を確認すると、他のページ間を移動する/現在のページを更新するときに、agecheck div がランダムかつ定期的に一瞬表示されることです。
これに対する最善のアプローチは、agecheck div がデフォルトで常に非表示になり、Cookie が null の場合、またはユーザーが「いいえ」をクリックした場合にのみ表示されるように、スクリプトを再コーディングすることだと思います。JavaScript と Cookie に関する私の理解は非常に限られているため、これに関するガイダンスを探しています。
年齢チェック機能は次のとおりです。
function checkAge(){
jQuery('html').css('overflow','hidden');
jQuery('body').css('overflow','hidden');
jQuery('body').css('height','100%');
jQuery('html').css('height','100%');
checkCookie();
// check age will need to check this
if(ofAge){
jQuery("#ageCheck").hide();
initPage();
}else{
jQuery('#ageCheckYes').click(is21);
jQuery('#ageCheckNo').click(isNot21);
}
};
//
// if the user is of age, animate in page
function is21(){
setCookie();
var h = jQuery(document).height();
// animate the div off
jQuery('#ageCheckBeerBG').animate({ top:h + 300 }, 2000+h);
jQuery("#ageCheck").delay(900).fadeOut("fast", function() {
initPage();
});
}
//
// user is not 21 send them on there way
function isNot21(){
alert('I am sorry you must be 21 or older to enter.')
};
//
そして、ここにクッキーチェックコードがあります:
function setCookie(){
document.cookie = "age_verified=true"
};
// check for cookie //
function checkCookie(){
var thiscookie = getCookie("age_verified");
if (thiscookie!="true"){
ofAge=false;
}else{
ofAge=true;
}
};
function getCookie(c_name){
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++){
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
console.log(unescape(x));
if (x==c_name){
return unescape(y);
};
};
};
前もって感謝します!