PDA

View Full Version : DHTML Modal window v1.1.



armasmike
05-08-2008, 03:18 AM
I really like this script
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm
DHTML Modal window v1.1.

But i want the window to popup everytime the page loads but if the user click a button or check box that says "don't open anymore" Then it will stop opening for that user.

How can that be done with this scripted ?

armasmike
05-09-2008, 03:35 PM
Is there anyone that can help me ?

ddadmin
05-10-2008, 03:10 AM
Sure, try the below modified modal.js file. Then, whereas you may have something like:


var 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")

You can now add inside agreement.htm a link that when clicked on, closes the modal window plus prevents it from popping up for x days:


<a href="javascript:parent.agreewin.dismiss(2)">Dismiss Window for 2 days</a>

Make sure the variable names in red match up.

armasmike
05-10-2008, 04:08 AM
That is great how do i turn that in to a check box ?

ddadmin
05-10-2008, 08:20 AM
Well, you could do something like the following:


<form>
<input type="check" onClick="if (this.checked) parent.agreewin.dismiss(2)" /> Dismiss Box
</form>

That should do it.

armasmike
05-10-2008, 03:24 PM
uuumm i like it but if i want it to come back i have to wate untill the days are up.

i tryed this


<form>
<input type="check" onClick="if (this.checked) parent.agreewin.hide()" /> Dismiss Box
</form>

that didn't work i want it to have a check box. And if it stayed checked then never open again. If the user un-checks it re-open the popup.

phpsales
05-10-2008, 04:33 PM
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


<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>

armasmike
05-10-2008, 05:12 PM
o your good thast great i will play with the code some more later to night

BIG thank you