PDA

View Full Version : DHTML Modal window: close window when veil is clicked?



Luterin
10-10-2007, 03:06 PM
1) Script Title:
DHTML Modal window v1.01

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

3) Describe problem:
I use the Window Widget and Modal features without any problem that I haven't managed to solve myself, but now I thought it would improve my site if I could close the popped up "window" by clicking outside it instead of a close button.

Easiest way should be to add some onClick on the veil, or so I figured, but I didn't figure out how to actually do it. Atleast not fast enough, so thought I might aswell ask the wise people here.

Tried to add an onClick to the <div> at the bottom of modal.js , which might very well be the easy way to do it, but I didn't get it right. Most likely some issues with the object, cause I always seem to mess/mix them up.

So any suggestion is greatly appreciated.

boogyman
10-10-2007, 03:11 PM
onclick="window.close()" should work

Luterin
10-10-2007, 03:44 PM
Thanks, but that didn't work. But I guess that "window.close()" actually needs to be something else, like either "this.something.somethingelse.close()" or "document.modalwindowsomething.something.close()".

boogyman
10-10-2007, 03:50 PM
oops sorry,



self.close()

will close the current window

window.close() is used for external windows

Luterin
10-10-2007, 04:18 PM
Thanks, but I think you have missunderstood me. (or I'm missunderstanding something you're saying :) )

It's not an actual window that I want closed, its the popup window widget that "DHTML Modal Window" creates that I want to be closed when someone clicks outside that "window", which would be on the veil which is behind that "window". Aswell as removing the veil aswell, but the close() function for modal window object handles that.

So all what I need to do is link that close() function to the <div> object which is created in the 2nd to last line in modal.js.

Perhaps that is what you are trying to do and I just dont understand it, but changing that line to the following doesnt work.


document.write('<div id="interVeil" onClick=\'self.close()\'></div>')

Luterin
10-10-2007, 05:14 PM
I solved it, but in an ugly way. I did:


document.write('<div id="interVeil" onClick=\'mymodalwindow.hide();\'></div>')

where "mymodalwindow" is the name of the window I assign when I create it with dhtmlmodal.open.

But there must be some better way to do this, as this only works on a window I've named to "mymodalwindow", and I would prefer if it actually closed whatever modal window that was open, instead of one named just this way.