Ricky
Ricky

Reputation: 3

Retrieving iframe contents after a form submitted to it

I have a form with an iframe as its target, and I want to retrieve its contents after the form has been submitted.

The problem is if I do something like:

$('form').submit(function (e) {
    e.preventDefault();
    var content = $('iframe').contents();
});

I get nothing because the form only submits after this. Is there any event that I can use AFTER the iframe received its content?

Thanks.

Upvotes: 0

Views: 1060

Answers (1)

Kevin B
Kevin B

Reputation: 95017

Try using the load event of the iframe.

$("iframe").load(function(){
  var response = this.document.getElementsByTagName("body").innerHTML;
  alert(response);
});

Upvotes: 1

Related Questions