View Full Version : Want to Call OnClose function when Modal Window Closes

01-29-2009, 07:38 PM
1) Script Title: DHTML Modal

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

3) Describe problem:
Hi i have successfully inlcuded the Modal Window script in my page. Now i want to Call The dthmlmodal.onclose function when the User clicks the (X) image button on top right of the modal window. please help me with it. Thanks

01-29-2009, 09:19 PM
This was done intentionally to provide a way for users to dismiss the modal window no matter what, such as if an error in the code you've added to the onclose() event causes it to never turn true. Anyhow, to bypass that and have the "x" button also trigger the onclose() event, inside modal.js, try commenting out the below two lines:

//if (typeof forceclose!="undefined")
//t.onclose=function(){return true}

01-29-2009, 09:25 PM
Hi thanks for the reply,

i tried to comment out the line. but its still not calling the function.

any ideas?


01-29-2009, 09:50 PM
That should do it actually. Please post a link to the page on your site that contains the problematic script so we can check it out.

01-29-2009, 09:53 PM
Its still in test Enviornment. we havent deployed it to production yet

01-29-2009, 10:34 PM
Upon testing, it seems the onclose() event does fire with the changes I made above, but only if the modal window is an Ajax or Inline based, and not IFRAME window. I'm not quite sure yet why this is so. Before we continue, have you tried the suggestion posted near the end of this thread: http://www.dynamicdrive.com/forums/showthread.php?t=18354 ?

01-29-2009, 10:39 PM
Ok i tried with it and it worked but other issue got popped.

Actaully i was closing the window using Window.close function to close the modal window which was working for me (on click of a button on the modal window). But now that event is not firing up i guess.

Anyways i will also try to find some workaround for me in this case. if you have any other suggessions please do tell me.


07-22-2010, 02:56 PM
I had this same problem and I'm happy to hear that other people have worked it out.
But my problem is that I didn't want to change the code in the delivered library (always a bad idea because when you upgrade you lose your changes)
So just a tip for anybody else, at startup when you load your page, or when you make your modal window, whenever, do this, and it will override their close function with one that does call onclose when user clicks the X

dhtmlmodal.close = function(t, forceclose){ //DHTML modal close function
t.contentDoc=(t.contentarea.datatype=="iframe")? window.frames["_iframe-"+t.id].document : t.contentarea; //return reference to modal window DIV (or document object in the case of iframe
if (dhtmlwindow.close(t)) //if close() returns true

12-02-2010, 01:15 PM
my only problem is that onclose gives an error in IE with pdf front and so doesn't close.

the previous proposed from Nixonsoe gave me the error :

"interface is not supported"

anyone got the answer yet? thanks .