...

View Full Version : Problems Transfering div contents x-browser



denizedenez
03-25-2005, 03:36 AM
Hello friends

I have the follow html page (do you can copy and save as test.htm, by example)

<div id="divOrigin">
<STYLE> <!-- .Test1 { color: #0000FF; font-weight: bold } .Test2 { color: #FF0000; font-weight: bold } --> </STYLE>
<span class='Test1'>Test1</span>
<span class='Test2'>Test2</span>
</div>
<div id="divDestination"></div>

<SCRIPT type="text/javascript">
<!--

function CopyContents(div1, div2)
{
div2.innerHTML = div1.innerHTML;
}

someDiv = document.getElementById("divOrigin");
otherDiv = document.getElementById("divDestination");

CopyContents(someDiv,otherDiv);

alert(someDiv.innerHTML);
alert(otherDiv.innerHTML);

//-->
</SCRIPT>

Please, check the contents of divOrigin, and the 2 alertboxes in Internet Explorer and FireFox...

IE (Alert1):
<STYLE> <!-- .Test1 { color: #0000FF; font-weight: bold } .Test2 { color:
#FF0000; font-weight: bold } --> </STYLE>
<span class='Test1'>Test1</span>
<span class='Test2'>Test2</span>

IE (Alert2), FireFox(Alert1) and FireFox(Alert2):
<span class='Test1'>Test1</span> <span class='Test2'>Test2</span>
I wish one EXACT COPY of contents from divOrigin to divDestination, but I know not how I can do it works in Firefox and IE... I need what all alerts show equals of IE(Alert1).

Someone can help me?

Denize

Kor
03-25-2005, 01:07 PM
looks like a homework, and usually we don't do others' homeworks... :D Except maybe if you have already worked till a point where we can show you the error/nest step/debugging process.

So, can u give us more details and what have you build so far?

denizedenez
03-25-2005, 02:07 PM
looks like a homework, and usually we don't do others' homeworks... :D
Kor, sorry but I don't understood.... what one homework have with my code snippet?

I think what I showed to you what I have tested very well the code (as in IE as in Firefox) and I showed the results in both browsers...


Except maybe if you have already worked till a point where we can show you the error/nest step/debugging process.

Well, if your need of more details... In my website the 2 divs are in separated frames, then I need transfer the html in div1 to div2, but not works... I did this small, easy-to-understand sample reproducing the problem... But appears what you think what is one homework?

So, can u give us more details and what have you build so far?

I have tryied this too:


function CopyContents(div1, div2)
{
var content = div1.innerHTML;
for (var i=0; i<content.length; i++)
{
var theChar = content.charAt(i);
if (theChar == "<")
{
theChar += "\<";
}
div2.innerHTML += theChar;
}
}
But this not work too...

I need this to one urgent project, and I know not what I can do... Javascript is too odd...

Regards
Denize

Kor
03-25-2005, 04:23 PM
I need transfer the html in div1 to div2,

Ok now...
1. Where should be the action (onclick, for instance). On parent?
2. What you wanna copy? Text, html code?

To reach the frames from another frame or from parent, you may try the reference

top.frames['framename'].object
top.frames['framename'].somefunction()

denizedenez
03-25-2005, 09:16 PM
1. Where should be the action (onclick, for instance). On parent?

My action is happening in onload. I have not problem with this, the function is called correctly


2. What you wanna copy? Text, html code?

Here is the problem.. I wish transfer this HTML code:

<STYLE> <!-- .Test1 { color: #0000FF; font-weight: bold } .Test2 { color: #FF0000; font-weight: bold } --> </STYLE>
<span class='Test1'>Test1</span>
<span class='Test2'>Test2</span>
Including the <Style> tag... but the <Style> is not tranfered...

What I can do?

Garadon
03-26-2005, 09:45 AM
This is just my own explanation not sure its true.


But styles are global, so nomatter where you define the style its applies to all elements fills the criteria for getting the style.

<element class="t">
<style>.t{}<style>

So my presumption is that it is not considered any part of the inner of a html tag since it still applies to the out side of the tag in which it is written. And copying such a global tag to several parts of a document don't add anything ekstra.

But then again I migth be wrong and its a bug :).

denizedenez
03-26-2005, 07:50 PM
This is just my own explanation not sure its true.


But styles are global, so nomatter where you define the style its applies to all elements fills the criteria for getting the style.

<element class="t">
<style>.t{}<style>

So my presumption is that it is not considered any part of the inner of a html tag since it still applies to the out side of the tag in which it is written. And copying such a global tag to several parts of a document don't add anything ekstra.

But then again I migth be wrong and its a bug :).

Perfect, Garadon, you are right. :thumbsup:

But I need this my code to transfer from one frame to another, i.e., from one page to another. I know what I can put all in one .css file and do one reference, but appears strange to me what both Firefox and IE we cannot perform this simple operation, of copy ALL div contents to another div, including style tags...

Thank you very much :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum