You would want to use a checkbox and set a cookie pending I agree. Below is a quick example (tested in IE7 and Firefox). Test live version here: http://phpscriptindex.com/dhtmlmodal/demo-modal.htm
HTML Code:
<label><input type="checkbox" id="agreeCBox" onclick="if(!this.checked) popAgree();" />I agree to this page's terms of service</label>
<script type="text/javascript">
//w3c setCookie Module -- http://www.w3schools.com/JS/js_cookies.asp
function setCookie(c_name,value,expiredays){
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
//w3c getCookie Modue -- http://www.w3schools.com/JS/js_cookies.asp
function getCookie(c_name){
if(document.cookie.length>0){
c_start=document.cookie.indexOf(c_name + "=");
if (c_start!=-1){
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(";",c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return null;
}
var agreeStatus = getCookie('agree');
var agreeCBox = document.getElementById('agreeCBox');
if(agreeStatus=='1'){
agreeCBox.checked = true;
}else{
popAgree();
}
function popAgree(){
parent.agreewin=dhtmlmodal.open("agreebox", "iframe", "modalfiles/agreement.htm", "This Page's Terms of service", "width=590px,height=450px,center=1,resize=1,scrolling=0", "recal");
agreewin.onclose=function(){ //Define custom code to run when window is closed
var theform=this.contentDoc.getElementById("eula") //Access form with id="eula" inside iframe
var yesbox=theform.eulabox[0] //Access the first radio button within form
var nobox=theform.eulabox[1] //Access the second radio button within form
if (yesbox.checked==true){
alert("You agreed to the terms")
setCookie('agree','1',1);
agreeCBox.checked=true;
}else if(nobox.checked==true){
alert("You didn't agree to the terms")
setCookie('agree','1',-1);
document.body.innerHTML = 'Access denied';
}
return true //Allow closing of window in both cases
}
}
</script>
Bookmarks