PDA

View Full Version : DHTML Modal onclose events not working



ezzatron
12-17-2008, 04:56 AM
1) Script Title:
DHTML Modal window v1.1

2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/dhtmlmodal.htm

3) Describe problem:
onclose events do not work at all when using modal windows. You can reproduce this by trying the following code:


var mywindow = dhtmlwindow.open("mywindow", "inline", "You will see a message when closing this window", "Window");
mywindow.onclose = function(){ alert("This message is displayed"); return true; };

var mymodal = dhtmlmodal.open("mymodal", "inline", "You will not see a message when closing this window", "Modal");
mymodal.onclose = function(){ alert("This message is never displayed"); return true; };

Looking at the source code, the problematic lines are in modal.js, lines 23, 56 and 57.

ddadmin
12-17-2008, 10:55 AM
Actually, this is the way the DHTML modal is intended to work. The onclose event in this case does not fire when the user clicks on the close ("x") icon, only when you try to call modalinstance.hide() in your code within the contents for the window. In the demos, you can see this in the 2nd example (Sign up for our newsletter)- entering an invalid email triggers the onclose event and causes the window to remain open, though clicking on the "close" icon will bypass everything and just close it.

The reason for this behavior is so the user always has the final say in dismissing a modal window, which if not basically renders the page inaccessible. This can happen if there's an error in your onclose event code that returns false and causes the window to never close.

If you're asking how to modify the above so onclose in DHTML modal behaves just like it does in the default DHTML Window script, let me know.

patrict
06-10-2009, 08:50 AM
Actually, this is the way the DHTML modal is intended to work. The onclose event in this case does not fire when the user clicks on the close ("x") icon, only when you try to call modalinstance.hide() in your code within the contents for the window. In the demos, you can see this in the 2nd example (Sign up for our newsletter)- entering an invalid email triggers the onclose event and causes the window to remain open, though clicking on the "close" icon will bypass everything and just close it.

If you're asking how to modify the above so onclose in DHTML modal behaves just like it does in the default DHTML Window script, let me know.

Hi DD Admin,

I would like to know how to modify the modal code so that it fires the onclose event when the user clicks on the close ("x") icon please :)

Many thanks
Patric

jsherk
12-18-2009, 09:47 PM
Yes, I would also like to know how to fire the onclose event when the X is clicked to close the window.

ddadmin
12-18-2009, 11:18 PM
There are a few threads on this already actually, ie: http://www.dynamicdrive.com/forums/showthread.php?t=41211