Richard Cornford wrote:
A table is not an array it is a host object (DOM Element).
It most certainly is
For the best cross-browser support named frames are best referenced as
named properties of the global - frames - collection (of the parent
frame):-
Point taken but judging from you comment this is not where the issue lies
top.frames.A.tableVar = . etc.
So you are assigning a reference to an element of a document in one
frame to a variable in another.
Correct
When you change the contents of a frame you destroy the document it
contains. All of the elements of that document become available for
garbage collection. Holding a reference to one of those elements in
another frame should (may) prevent the element itself and its
descendants from being garbage collected but as its document object has
been destroyed it is probably unrealistic to expect that element to
remain functional.
Ahh, I take your point but wouldn't that imply that this should not work
with Gecko based browsers either? Which (unfortunately?) it does!
It is also usual for DOM implementations not to allow an Element (or
Node) from one document to be inserted in another (except using the
document.importNode method, which actually creates a copy of the
"imported" Node for the current document and leaves the original
unchanged).
Ok, updating my DOM knowledge here. Does this mean that every frame has got
its own DOM or is the DOM still 'defined at browser level' if you wish and
are the frames just nodes in the overall structure?
I was under the impression that the latter is the case.When tested with something simple like a String (instead of a table)
the above mechanism works as expected.
Strictly the previous value assigned to the variable in the other frame
also "works", in the sense that it has been assigned a reference to an
object and it is still holding that value after the page has changed. It
is just that the object referred to has been radically altered by the
fact that its document has been destroyed (in addition, its global
context/window(frame) object has also been distorted).
In summary: the variable that holds the reference indeed still contains it.
Because 'further down' in the reference part of it is 'linked' to a
'disappearing' document this part becomes 'stuffed up.
I (think) I can follow the reasoning but I'm still not getting the fact
that Gecko is *not* compliant with *this* behaviour.
Actually, should it not be irrelevant how complex a structure is? Either
you loose cit or you don't. the table as a whole is part of the document so
wouldn't it be more logical for it to disappear as a whole and not just its
rows?
Trying to store a reference to a table is a shortcut to trying to store
the information within that table,
Absolutely correct, basically its a state keeping issue. probably the best solution is to
extract the required information from the table and store that in a
JavaScript object belonging to frame A. Probably an object customised to
ease the process of restoring/inserting the information to new elements
created in the other frame.
Ok, couldn't cloneNode be used to basically 'do' this.
On init one just clones the 'skeleton'
On subsequent modification one just clones the required part and inserts it
into the static structure.
IF the above would hold can I than still 'replace' the not required table
coming in on the new page with the 'stored' static one or would that result
in funny behaviour as well.
Following the code (part of the static frame) used by the 'dynamic' frame
to modify the structure shown.
Thx for the reply.
=============================================
var _staticTable;
var _tbodyRows;
/**
* This function is responsible for inserting a new tBody in an extisting
table.
* @param win = the window from where the function is called (mainContent)
* @param table = the ID of the table where the tbody needs to be inserted
*/
function createTbody(win, tBodyID) {
var windoc = win.document;
var myDiv = windoc.getElementById("doc");
// creates/ get an element of type TABLE
if (tBodyID=="" || !_staticTable) {
_staticTable = windoc.getElementById("treeTable");
return;
}
else {
var defaultTable = windoc.getElementById("treeTable");
myDiv.replaceChild(_staticTable, defaultTable);
}
// creates an element whose tag name is TBODY
var mytablebody = windoc.getElementById(tBodyID);
// creating all cells within the rows
for(var j=0, rLen=_tbodyRows.length; j<rLen; j++) {
// creates an element whose tag name is TR
var mycurrent_row=windoc.createElement("TR");
// start working on the columns
for(var i=0, cLen=_tbodyRows[0].length; i < cLen; i++) {
// creates an element whose tag name is TD
var mycurrent_cell=windoc.createElement("TD");
// creates a Text Node
var currenttext=windoc.createTextNode(_tbodyRows[j][i]);
// appends the Text Node we created into the cell TD
mycurrent_cell.appendChild(currenttext);
// appends the cell TD into the row TR
mycurrent_row.appendChild(mycurrent_cell);
}
// appends the row TR into TBODY
mytablebody.appendChild(mycurrent_row);
}
}