Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
129
rated 0 times [  130] [ 1]  / answers: 1 / hits: 108889  / 15 Years ago, thu, august 20, 2009, 12:00:00

Is there anyway to unload a page that has been loaded inside an iframe? I do not want to change the iframe src to a blank page if possible. I am basically looking for something that will do something like this $('#frameID').attr(src,); except that code does not seem to clear the previously loaded page.



Is there a unload function that I can call which will reset the iframe so that it does not have any content loaded inside?


More From » jquery

 Answers
18

The other solutions use innerHTML, which won't always work in XHTML. They also only clear document.body (anything in the <head> is still present). Here is a solution that uses the DOM:



var frame = document.getElementById(myFrame),
frameDoc = frame.contentDocument || frame.contentWindow.document;
frameDoc.removeChild(frameDoc.documentElement);


This solution uses innerHTML:



var frame = document.getElementById(myFrame),
frameDoc = frame.contentDocument || frame.contentWindow.document;
frameDoc.documentElement.innerHTML = ;

[#98862] Tuesday, August 18, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
milo

Total Points: 62
Total Questions: 99
Total Answers: 97

Location: Sweden
Member since Mon, May 8, 2023
1 Year ago
;