Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2010
    Posts
    405
    Thanks
    17
    Thanked 2 Times in 2 Posts

    close parent on iframed form submission

    I've got a couple limitations to what I can do, but my goal is to have a quick little script on a form page that listens for the form submission button to be clicked. When the form is clicked I want to do something like this: but not in jquery - just straightforward javascript.

    Code:
    <script type="text/javascript">
    
    $('#form124").submit( parent.closeIFrame('#Iframe1'); );</script>
    I can put the action in the parent window, but I can't touch the form tag itself, so I can't just place onsubmit="parent.closeIFrame();" in there.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    You can add an event listener to the <form>'s onsubmit, you know.

    Do it all via JS without touching the source code for the <iframe>.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,965
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Is this what you want?
    Code:
    document.getElementById('form124').onsubmit = function(e) {
        parent.closeIFrame('#Iframe1');
    };

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I don't think that's a good idea, Glenn. That *might* overwrite the onsubmit that already exists for the form. That's why I suggested adding an event listener.

    And in any case, I think he means he can't alter the source code for the iframe, meaning he has to do it from the parent window after getting a reference to the iframe, etc.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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