PDA

View Full Version : Close modal when click on background



Rodekode
11-22-2009, 07:40 PM
1) Script Title:
DHTML Modal window v1.1

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

3) Describe problem:
Is it possible to close a modal when clicking on the veil/background? I have tried these with no success:
A) document.write('<div id="interVeil" onclick="window.close()"></div>')
B) document.write('<div id="interVeil" onclick="self.close()"></div>')

BTW: Do you plan any update on the script? It would be cool if modal window in future will have fade-in when opened and fade out when closed :)

Best regards
Thomas

jscheuer1
11-23-2009, 08:04 PM
Here is a typical command to allow what you want:


document.getElementById('interVeil').onclick = function(){
agreewin.hide(document.getElementById('agreebox'), true);
};

It should follow the declaration (example below), where agreewin is the variable name to which the instance of dhtmlwindow was assigned and agreebox the id assigned for the the window that would be opened:


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


Notes: If you have an onclose defined for the dhtmlwindow, if it returns false, it will prevent the above from working. Also, if you have more than one dhtmlwindow, things could get a bit messed up, but a more complex command could probably be devised to handle that.

As to your second question, I'm pretty sure that will be coming, but cannot say for sure.

Rodekode
11-23-2009, 09:25 PM
Thank you John for reply. I will have a lot of dhtml-modals with dynamic assigned ID's from posts in a database. I use dhtml-modals to show additional info, videos, linked pages, etc. for each post returned by the database. I think the solution will be too complex to achieve (for me) so I will go with the default modal-script.

A bit off-topic: Do you know how to make the modal not-draggable and is it possible to assign a key-shortcut like cmd+x or esc to close the modal?

Again: Thank you for your time - it is much appreciated.

Best regards
Thomas

jscheuer1
11-24-2009, 12:46 AM
Well, it sounds to me like you might want Lightwindow:

http://www.stickmanlabs.com/lightwindow/

It would be a bit of a change, but it appears to have all of the functionality you want, including both clicking on the overlay to close and a fade in/out of the overlay. It's also very flexible - it can be invoked from a link with certain attributes or directly from javascript call as part of other code.

Rodekode
11-24-2009, 02:42 PM
Hello John,

Thanks again. I try the Lightwindow.

Best regards
Thomas