I'm trying to move an iframe from one position in the DOM to another. The moving itself is not a problem at all, but I experience a different behaviour between Firefox (1.5) and IE (6): As soon as I insert the iframe somewhere else, in Firefox the contents get reloaded, whereas in IE the iframe remains as it is. The latter one is the behaviour I'd require. Essentially I'd like to move the iframe and keep the state of it across the move operation. I narrowed my code down to the following minimal test:
test.html:
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <script type="text/javascript">
- var currentContainer = "container1";
- var otherContainer = "container2";
- function swap()
- {
- var cc = document.getElementById(currentContainer);
- var co = document.getElementById(otherContainer);
- var i = cc.getElementsByTagName("IFRAME")[0];
- co.appendChild(i);
- //cc.removeChild(i);
- var tmp = currentContainer;
- currentContainer = otherContainer;
- otherContainer = tmp;
- }
- </script>
- </head>
- <body>
- <a href="javascript:void(0);" onclick="swap();">swap</a>
- <div id="container1" style="width:200px; height:200px; background-color: red">
- Container1
- <iframe src="test1.html"></iframe>
- </div>
- <div id="container2" style="width:200px; height:200px; background-color: green">
- Container2
- </div>
- </body>
- </html>
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <script type="text/javascript">
- function loaded()
- {
- alert("loaded");
- }
- </script>
- </head>
- <body onload="loaded();">
- </body>
- </html>
Any idea how I can convince FF to behave like IE (just in this case of course ;-))?
Best regards,
Volker