Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a page with an iframe. In the iframe there’s a submit button. When I click the submit button I want the parent window to be updated. This is what I have done so far, and it works (the javascript is located in the parent window):

var myFrame = $('iframe');
myFrame.load(function() {
myFrame.contents().find('#publish').click(function() {

  myFrame.load(function() {
    location.reload();
  });

});
});

The code works. But I find the reload of the iframe unnecessary. Is there a better way to detect when "submit" is completed?

(I can’t reload the page only by “onclick” or relay on any delay. I must be sure that the submitting of the form is finished)

share|improve this question
parent window to be updated? or parent window to be reloaded? what is the update? – two7s_clash Apr 17 '11 at 20:36

3 Answers

$("#publish").click(function() {
    $('#inputs').ajaxSubmit({
        success:function(){
            //alert("Reload called");
            parent.location.reload();
        }
    });
 });

This worked.

share|improve this answer
Welcome to SO. There is no specific reference to Ajax in the question. It may be also a standard html form submit. – Tony Rad Nov 12 '12 at 4:40

You could have the form submission return a block of js:

<html>
<script>
 window.parent.document.jQueryFunction();
</script>
</html>

or, if you're open to plug-in, you could use the ajaxSubmit() method of the jQuery Form Plugin.

$myFrame.contents().find('form').ajaxForm({
  success: function() {
     // update parent
  }
});
share|improve this answer

Assuming publish is unique you can simply do so:

$(document).ready(function(){
  $('#publish').live('click', function(e){
     e.preventDefault();
     //Do whatever you want here
   });
});

Notice the live will bind the even to publish link at runtime.

share|improve this answer
Hi Naveed, you missed "});". But I can't see how this function will help me submit the form and reload the page. I want a function to detect when submit is sent. – Hakan Apr 17 '11 at 18:29
@Hakan, thanks fixed. Let me look into it again. – Naveed Ahmad Apr 17 '11 at 18:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.