Results 1 to 5 of 5

Thread: How to trap Close button click of modal window from the calling page

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

    Default How to trap Close button click of modal window from the calling page

    1) Script Title: :: DHTML Modal window v1.1

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

    3) Describe problem: I want to trap "Close" button(at the top right corner) click from my calling page. How can i do that?
    Present script only allow to trap close(parent.modalwindow.hode()) event inside modal window by using:-
    agreewin.onclose=function(){ //Define custom code to run when window is closed
    }
    .But due to some project requirement i need to find out when user click top close button to close the modal window.
    Please help.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    The calling page is the page that launched the window, not the page in the window. Do you really mean the calling page? If so, that's what:

    Code:
    agreewin.onclose=function(){ //Define custom code to run when window is closed
     }
    does. If you mean the page in the window:

    Code:
    parent.agreewin.onclose=function(){ //Define custom code to run when window is closed
     }
    I see an example is given:

    Code:
    mysurvey.onclose=function(){
     var iframedoc=this.contentDoc
     alert(iframedoc.body.innerHTML) //alert entire body content of iframe
     alert(iframedoc.getElementById("myname").value) //alert value of form field with id="myname"
     }
    That runs on the calling page, but accesses information inside the window. If you want to access information on the calling page use ordinary javascript, without the contentDoc object.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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

    Default

    Thanks John for your prompt reply.
    Yes you are correct that "Calling page" means the page from where i have called modal window page. Like from A page, i want to call B page inside modal window.So here "A" is my calling page.
    Now, problem is if i click top right Close icon(which is not part of any page,comimg with modal window), i am not getting any event in my calling page,here in "A" page.

    agreewin.onclose=function(){ //Define custom code to run when window is closed
    }
    The above code is only working if i forcefully or you can say using code,close the modal window,but the above code is not working if i close modal window by clicking "top Close" icon (check red circle of attached image)Attachment 4009.
    So how to trap close event?

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Yeah. I had recently been looking at the parent script (the Window Widget) for someone else and assumed it would work the same way, at least as far as the close button is concerned.

    But it doesn't. I didn't write either of these, so I can't say for sure why - what the logic was in that. I also cannot be 100% sure that my fix won't mess something else up. But it seems fine in limited testing.

    Here's what to do. Using a text only editor like NotePad, edit the modal.js file. Find the close function (around line #54) and comment out (red slashes) the two highlighted lines as shown:

    Code:
    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 (typeof forceclose!="undefined")
    		//t.onclose=function(){return true}
    	if (dhtmlwindow.close(t)) //if close() returns true
    		this.closeveil()
    },
    Added Later:
    I see now that the email box cannot be closed without a "valid" email, not even with the close button. But if the onclose function were written differently and the form returned a different onclick/onsubmit .hide() event than the box itself, it would be fine with the code change as outlined above.
    Last edited by jscheuer1; 08-07-2011 at 03:32 PM. Reason: saw the potential problem - later precision in explanation
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    dibakar (08-07-2011)

  6. #5
    Join Date
    Nov 2009
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks John for your help. Now i can manage rest of the my requirements.

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
  •