473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Contents Reloaded on Inserting an IFRAME Into DOM

3
Hi,

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
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.             var currentContainer = "container1";
  5.             var otherContainer = "container2";
  6.  
  7.             function swap()
  8.             {
  9.                 var cc = document.getElementById(currentContainer);
  10.                 var co = document.getElementById(otherContainer);
  11.                 var i = cc.getElementsByTagName("IFRAME")[0];
  12.                 co.appendChild(i);
  13.                 //cc.removeChild(i);
  14.                 var tmp = currentContainer;
  15.                 currentContainer = otherContainer;
  16.                 otherContainer = tmp;
  17.             }
  18.  
  19.         </script>
  20.     </head>
  21.     <body>
  22.         <a href="javascript:void(0);" onclick="swap();">swap</a>
  23.         <div id="container1" style="width:200px; height:200px; background-color: red">
  24.             Container1
  25.             <iframe src="test1.html"></iframe>
  26.         </div>
  27.         <div id="container2" style="width:200px; height:200px; background-color: green">
  28.             Container2
  29.         </div>
  30.     </body>
  31. </html>
  32.  
test1.html
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript">
  4.             function loaded()
  5.             {
  6.                 alert("loaded");
  7.             }
  8.         </script>
  9.     </head>
  10.     <body onload="loaded();">
  11.     </body>
  12. </html>
  13.  
On the first page load an alert box pops up. Nothing wrong with that. But on clicking the "swap" link in Firefox the alert keeps popping up whereas in IE it doesn't.

Any idea how I can convince FF to behave like IE (just in this case of course ;-))?

Best regards,
Volker
Feb 15 '07 #1
4 2241
iam_clint
1,208 Expert 1GB
best way i can think of is to have 1 div and move the entire div
or have you tried setting container 2's innerHTML to container1's innerHTML
Feb 15 '07 #2
volker
3
Thanks very much for your suggestions. Unfortunately neither of them work. I also tried to use an <object type="text/html"> instead of an iframe, with the difference that now IE also behaves like FF. Any other ideas?
Feb 16 '07 #3
iam_clint
1,208 Expert 1GB
i took your code and tried things left and right in firefox i couldn't come up with a good conclusion on how you would make a work around for this.
Feb 16 '07 #4
volker
3
No worries. Thanks anyway for your efforts. I guess I have to accept the behaviour as it is.
Feb 19 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: John Chen | last post by:
I need to use iframe to create a floating frame. But the contents in the iframe is not a external html file. Rather, it will be dynamically created by jsp. How can I set the src attribute to a URL...
4
by: primary0 | last post by:
Hi, I have a page containing an external javascript which loads an image onto the webpage. How would it be possible to use javascript to read the filname (and the dimensions) of the loaded image...
1
by: user | last post by:
I have a parent aspx page with a few iframes. Each of the iframes show an aspx page with a datagrid whose rows all show editable entry fields at all times. The user can enter values into the parent...
1
by: Steve Richter | last post by:
I have a simple table with two columns. The first column contains 5 lines of text. The second column contains an iFrame. The iFrame in turn contains a web page. The problem is it does not...
1
by: Mike | last post by:
I have an intranet page which has an iframe which links to a number of different possible .NET pages. In one of the embedded .NET pages (and soon to be others) we want to be able to capture...
1
by: jaktharkhan | last post by:
Hi, I really really need help in trying to figure out how can I do a CloneNode on an Iframe where the cloned IFRAME clones with all its contents?. Basically what I am doing is dynamically building...
2
by: bs9999 | last post by:
I'm using IFRAME to connect back to my ASP.NET page in order to fetch the FreeBox HTML Editor html contents and scripts (i do this apprach because the html editor is fairly heafty to send to the...
1
by: rissaofthesaiyajin | last post by:
I have a page with an iframe, and a Javascript function that I need to get the contents of the iframe - what I mean by that is, the text from the list.html file that's in the iframe. It's actually a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.