appendChild problem

A

alxwest

Hi

I'm trying to spread a table across a frameset. So I have index.htm
that has an iframe sourcing the frameset. What I'm trying to do is
create a table in index.htm to spread across the whole brower window.

My code, ran from within the frameset:

function Createtbl(){
var tbl = document.createElement('table');

tbl.height = "100%";
tbl.style.height = "100%";
tbl.width = "100%";
tbl.style.width = "100%";

var newRow = tbl.insertRow(-1);
var newCell = newRow.insertCell(-1);
newCell.innerHTML = "hello world";

var holder = top.document.createElement('div');
top.document.appendChild(holder);

holder.outerHTML = tbl.outerHTML;

}

The above doesn't work, the below only works in ie

If in index.htm I create a div tag with the id "holder":-


function Createtbl(){
var tbl = document.createElement('table');

tbl.height = "100%";
tbl.style.height = "100%";
tbl.width = "100%";
tbl.style.width = "100%";

var newRow = tbl.insertRow(-1);
var newCell = newRow.insertCell(-1);
newCell.innerHTML = "hello world";

var holder = top.document.getElementById('holder');
holder.outerHTML = tbl.outerHTML;

}

Any ideas to get this to work in firefox? And create the "holder"
dynammically?

NB: creating the table can't be top.document.createElement as the code
the generate it is another function used for various things.

Cheers

Alex
 
A

alxwest

Forgot to mention that I set the table to absolute and zindex to 2 so
appears over the iframe.

Cheers

Alex
 
J

Jeremy

Hi

I'm trying to spread a table across a frameset. So I have index.htm
that has an iframe sourcing the frameset. What I'm trying to do is
create a table in index.htm to spread across the whole brower window.

My code, ran from within the frameset:

function Createtbl(){
var tbl = document.createElement('table');

tbl.height = "100%";
tbl.style.height = "100%";
tbl.width = "100%";
tbl.style.width = "100%";

var newRow = tbl.insertRow(-1);
var newCell = newRow.insertCell(-1);
newCell.innerHTML = "hello world";

var holder = top.document.createElement('div');
top.document.appendChild(holder);

holder.outerHTML = tbl.outerHTML;

}

The above doesn't work, the below only works in ie

If in index.htm I create a div tag with the id "holder":-


function Createtbl(){
var tbl = document.createElement('table');

tbl.height = "100%";
tbl.style.height = "100%";
tbl.width = "100%";
tbl.style.width = "100%";

var newRow = tbl.insertRow(-1);
var newCell = newRow.insertCell(-1);
newCell.innerHTML = "hello world";

var holder = top.document.getElementById('holder');
holder.outerHTML = tbl.outerHTML;

}

Any ideas to get this to work in firefox? And create the "holder"
dynammically?

NB: creating the table can't be top.document.createElement as the code
the generate it is another function used for various things.

Cheers

Alex

A few considerations:

1) The innerHTML / outerHTML attributes are not reliable. You should
avoid using them, if possible.

2) Even assuming that they are reliable in and of themselves, they are
certainly NOT reliable if the element does not even exist in the
document. You have created an orphaned node (the table element) and it
has not necessarily been assigned any markup.

3) You are creating elements in one document, and then trying to append
them to an element in another document. This is not reliable (and in
fact, should not work). In a DOM2-compliant browser, you should be able
to use importNode to create a copy of the node in the target document,
but IE is not such a browser and does not implement this function.

If you describe in more detail what your goal is, and why you are doing
it (what do you mean by "spread a table across a frameset", and why are
you doing this?), then the group may be more able to suggest proper
methods for accomplishing your goal.

Jeremy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top