Advanced Search

Results 1 to 5 of 5

Thread: DHTML Modal onclose events not working

  1. #1
    Join Date
    Dec 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DHTML Modal onclose events not working

    1) Script Title:
    DHTML Modal window v1.1

    2) Script URL (on DD):
    http://www.dynamicdrive.com/dynamici...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:

    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.

  2. #2
    Join Date
    Aug 2004
    Posts
    9,862
    Thanks
    3
    Thanked 959 Times in 948 Posts
    Blog Entries
    15

    Default

    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.
    DD Admin

  3. #3
    Join Date
    Jun 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by ddadmin View Post
    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

  4. #4
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, I would also like to know how to fire the onclose event when the X is clicked to close the window.

  5. #5
    Join Date
    Aug 2004
    Posts
    9,862
    Thanks
    3
    Thanked 959 Times in 948 Posts
    Blog Entries
    15

    Default

    There are a few threads on this already actually, ie: http://www.dynamicdrive.com/forums/s...ad.php?t=41211
    DD Admin

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •