Javascript - Empty an iframe
Solved
le sparte
-
Chaostronix -
Chaostronix -
Hello,
My question is very simple: I have an iframe filled in Javascript with the command "document.write('my text')" and I’m looking for a way to clear it of its content so that with every user click, the old content of the iframe is overwritten by the new one.
Thanks in advance for your help ;-)
Configuration: Mac OS X Firefox 2.0.0.3
My question is very simple: I have an iframe filled in Javascript with the command "document.write('my text')" and I’m looking for a way to clear it of its content so that with every user click, the old content of the iframe is overwritten by the new one.
Thanks in advance for your help ;-)
Configuration: Mac OS X Firefox 2.0.0.3
4 answers
Look at the innerHTML side.
Usage:
You retrieve the element in the following way (let’s suppose your iframe is named 'toto' -> id='toto') and you replace its content with "".
var myIframe = document.getElementById('toto'); myIframe.innerHTML = "";
But having never used iframes, I’m not sure whether it’s a component like DIVs, or a component managed like a frame.
If it’s the first way, then the method above should work.
If an iframe is managed in the same way as a Frame, then you would need to do as follows:
var myIframe = parent.frame['toto']; myIframe.document.innerHTML = "";I’m not sure this works but it’s a lead (I can’t test, sorry). Good luck for the rest. -- ~ Don’t forget the "Resolved" tag when your problem is... resolved :) ~
Hello,
Why use document.write in the remplir function, and document.body.innerHTML in vider?
Why not use the same instruction in both functions?
If you replace the code in your 'remplir' function with this:
document.getElementById("htmle").contentWindow.document.body.innerHTML = "blablabla";
Will it work?
--
~ Do not forget the "Resolved" tag when your problem is... resolved :) ~
Thank you for your help, this helped me solve my problem.
I confirm the following syntax: document.getElementById('id_de_la_frame).contentWindow.document.body.innerHTML in order to read the content of my iframe.
Have a great day everyone.
I confirm the following syntax: document.getElementById('id_de_la_frame).contentWindow.document.body.innerHTML in order to read the content of my iframe.
Have a great day everyone.
Hi,
After doing:
document.getElementById("htmle").contentWindow.document.write('blablabla');
You should do:
document.getElementById("htmle").contentWindow.document.close();
Otherwise the document remains open and the browser spins its wheels.
This allows your clear function to work correctly as many times as you want.
After doing:
document.getElementById("htmle").contentWindow.document.write('blablabla');
You should do:
document.getElementById("htmle").contentWindow.document.close();
Otherwise the document remains open and the browser spins its wheels.
This allows your clear function to work correctly as many times as you want.
If you click remplir, it works. If you click effacer, it works. But if you click remplir again... it doesn’t work! How can I avoid this? Thanks in advance for your help! ;-)