954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

jQuery Get iFrame Content

Hello. I am using an iframe in my page to submit a form to so that it can upload a file - since you can't do this through the jquery ajax function. I have everything working, but I want to be able to hide the iframe and get the content of it, and put just the content inside of it into another div on the page.

I have tried alot of things, but I think this one was probably closest:

$("#myframe")[0].contentDocument;

This ended up getting me a value type of "Object HTMLDocument", I just can't figure out how to get the content as a string so that I can put it into the div I want.

Thank you for any help you can give me!

kroche
Junior Poster in Training
52 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

I have continued to look around for a solution, and I re-ran my page again and realized that I was being alerted of the iFrame content before that content was in the iFrame to begin with. So what I did was looked to see if the iFrame had been completely loaded, then I got the content and put it where I wanted it.

Code:

function getIframeContents(){
	$("#fileuploadframe").load(function(){
		response = $("#fileuploadframe").contents().find("#returnValue").html();
		alert(response);
		$("#responses").html(response).show();
	});	
}

This function is fired onsubmit of a form.

kroche
Junior Poster in Training
52 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: