年龄验证-关闭对话框窗口
Age Verification - Close Dialog Window
使用Nation Builder作为客户网站的平台,需要创建一个年龄门。我想在一个单独的页面上进行年龄验证,但显然它不能与这个平台一起工作,所以我使用Jquery对话框来显示在主页的顶部。我得到验证年龄工作的代码,但需要调整它,以关闭小部件UI,而不是一个url重定向。
我不是编程专家,所以任何帮助和简化它将是感激的。这里有一个链接。http://patricialourenco.com/test.html干杯!
var ageCheck = {
//Set the minimum age and where to redirect to
minimumAge : 13,
userIsOldEnoughPage : "http://www.bullyproject.com",
userNotOldEnoughPage : " http://www.pacerkidsagainstbullying.org/#/home",
//Leave this stuff alone please :)
start: function() {
this.setUsersBirthday();
if (this.userIsOverMinimumAge()) {
this.setCookie("usersBirthday",this.usersBirthday,30);
window.location = this.userIsOldEnoughPage;
} else{
this.notMinimumAge();
};
},
usersBirthday : new Date(),
setTheMonth : function() {
var selectedMonth = document.getElementById("month").value;
if (selectedMonth === "1") {
this.setDaysForMonth(29);
}
else if (selectedMonth === "3" ||
selectedMonth === "5" ||
selectedMonth === "8" ||
selectedMonth === "10") {
this.setDaysForMonth(30);
}
else {
this.setDaysForMonth(31);
};
},
setDaysForMonth : function(x) {
var daySelectTag = document.getElementsByName('day')[0];
daySelectTag.options.length = 0;
for(var i=1; i <= x; i++) {
daySelectTag.options.add(new Option(i, i));
}
},
setUsersBirthday: function() {
var usersMonth = document.getElementById("month").value;
var usersDay = document.getElementById("day").value;
var usersYear = document.getElementById("year").value;
this.usersBirthday.setMonth(usersMonth);
this.usersBirthday.setDate(usersDay);
this.usersBirthday.setFullYear(usersYear);
},
setMinimumAge: function() {
var today = new Date();
today.setFullYear(today.getFullYear() - this.minimumAge);
return today;
},
notMinimumAge : function() {
window.location = this.userNotOldEnoughPage
},
userIsOverMinimumAge: function () {
if (this.usersBirthday < this.setMinimumAge()) {
return true;
}
},
setCookie: function (c_name,value,exMinutes) {
var exdate=new Date();
exdate.setMinutes(exdate.getMinutes() + exMinutes);
var c_value=escape(value) + ((exMinutes==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
},
getCookie: function (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("="));
x=x.replace(/^'s+|'s+$/g,"");
if (x==c_name)
{
return unescape(x);
}
}
},
checkCookie: function () {
var usersBirthday=this.getCookie("usersBirthday");
if (usersBirthday==null || usersBirthday=="") {
window.location = "ageCheckTester.html";
}
}
}
我想你正在寻找。close方法-在用户按下按钮提交他们的年龄后,您将如何使用它:
$('#dialog-modal').dialog('close'); //hides modal, shows content behind
更多关于jQuery UI对话框的文档:
http://api.jqueryui.com/dialog/method-close
编辑:下面是如何更新start()方法:
start: function() {
this.setUsersBirthday();
if (this.userIsOverMinimumAge()) {
this.setCookie("usersBirthday",this.usersBirthday,30);
$('#dialog-modal').dialog('close');
} else{
this.notMinimumAge();
};
},
和一个JSFiddle演示:http://jsfiddle.net/donmccurdy/czERa/
编辑#2 -(回答OP关于检查每个页面cookie的问题)
检查cookie的代码中有一些错误。我已经更新了JSFiddle,这里是错误的快速版本:
1)代替你目前拥有的总是显示对话框的代码,先检查cookie。这样的:
$(function() {
window.ageCheck.checkCookie();
});
2)更新checkCookie()方法以在必要时显示对话框:
checkCookie: function () {
var usersBirthday=this.getCookie("usersBirthday");
if (!usersBirthday) {
// unknown age - show dialog.
$( "#dialog-modal" ).dialog({modal: true});
return;
}
this.usersBirthday = new Date(usersBirthday);
if (this.userIsOverMinimumAge()) {
$('#dialog-modal').hide();
// user is > 13, don't show dialog.
} else {
// user is < 13, redirect to another page.
this.notMinimumAge();
}
}
3)你的getCookie方法有一个bug,因为你返回的是"usersBirthday"而不是生日本身。固定:
getCookie: function (c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
//split on '=', then check cookie
x=ARRcookies[i].split('=');
if (x[0]===c_name){
return unescape(x[1]);
}
}
},
相关文章:
- 在 Telerik RadGrid 中单击复选框时打开对话框窗口
- 当对话框窗口打开时,使父页模糊
- 如何使用JavaScript关闭此对话框窗口
- Ajax 请求未拉出 jQuery 对话框窗口
- Cke对话框窗口增加了简单的功能
- Ajax 对对话框窗口的响应在第二次尝试时不显示更改的值
- 堆栈溢出如何创建模式对话框窗口
- 如何从IE和Chrome浏览器中的显示模式对话框窗口返回数组对象
- Facebook:对话框窗口弹出 - 导航离开时,我该怎么做
- CKEditor:在插件“图像”的对话框窗口中设置输入字段的值
- 根据 ScriptUI 中的操作更改对话框窗口的大小
- 将选定行的数据从对话框窗口传递到主页
- 模式对话框窗口中的不可见融合图未导出
- 从jquery移动对话框窗口执行父函数
- Indesign Script JS:编辑文档文本框内容并返回对话框窗口
- 通过javascript控制自定义对话框窗口的字段
- 如何保存对话框窗口的位置
- Javascript 对话框窗口关闭
- 年龄验证-关闭对话框窗口
- 如何打开一个对话框窗口