最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Reload page after submit in iframe (javascriptjquery) - Stack Overflow

programmeradmin5浏览0评论

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 pleted?

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

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 pleted?

(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 asked Apr 17, 2011 at 18:08 HakanHakan 3,89514 gold badges47 silver badges66 bronze badges 2
  • parent window to be updated? or parent window to be reloaded? what is the update? – two7s_clash Commented Apr 17, 2011 at 20:36
  • How do you solve this in the end? – Moncho Chavez Commented Dec 10, 2013 at 22:37
Add a ment  | 

3 Answers 3

Reset to default 0

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.

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
  }
});
$("#publish").click(function() {
    $('#inputs').ajaxSubmit({
        success:function(){
            //alert("Reload called");
            parent.location.reload();
        }
    });
 });

This worked.

发布评论

评论列表(0)

  1. 暂无评论