Is there any way to deep clone iframe?
Basic jQuery cloning just makes another iframe with the same src. What I want to achieve is a way to clone the iframe and it’s exact current content (ie. any possible input values, any DOM modifications through javascript etc.).
var clone = iframe.contents().find('html').clone();
When i clone the HTML attribute and all its children’s, modifications etc I have these problems:
-
I’m missing the DOCTYPE
-
how do I insert it into the new iFrame?
If you clone the
iframecreating anotheriframethen you deep clone youriframe! It’s source is somewhere else and it’ll be downloaded when you assign itssrcattribute.Test
Imagine you have as source a (non cached) page that prints the current time. Put an
iframeon your page, wait 10 seconds then clone it. The newiframewill download its content and the 2ndiframewill have a different content (the time).“Real” deep cloning
EDIT: if you need a deep raw clone you may get the innerHTML and inject it inside the iframe. Solution from Michael Mahemof: