Cannot modify a table in a self created window

U

user

I created a window with

var mywindow = window.open( "some/local.html", "mywindow", "width=...,
"height=...., ..." );

The window shows up. It contains a table.

<table>
<tr>
<td>begin</td>
</tr>
<tr id="here">
<td>end</td>
</tr>
</table>

Trying to modify the table (with the following code) fails using Mozilla
1.5 (IE6 works):

var here = mywindow.document.getElementById( "here );
var tr = mywindow.document.createElement( "tr" );
var td = mywindow.document.createElement( "td" );

var txt = mywindow.document.createTextNode( strType );

td.appendChild( txt );
tr.appendChild( td );

here.parentNode.insertBefore( tr, here );

alert( here.parentNode.innerHTML ); show that the new node exists.

But when executing this in Mozilla the new table row is not displayed.
 
K

kaeli

[email protected] enlightened us said:
I created a window with

var mywindow = window.open( "some/local.html", "mywindow", "width=...,
"height=...., ..." );

The window shows up. It contains a table.

When making dynamic tables, use thead, tbody, and tfoot as appropriate.
It made things easier for me and new scripts that use them are easier to
use with your tables.
<tr>
<td>begin</td>
</tr>
<tr id="here">
<td>end</td>
</tr>
</table>

Trying to modify the table (with the following code) fails using Mozilla
1.5 (IE6 works):


But when executing this in Mozilla the new table row is not displayed.

A script I downloaded had a comment in it about NN/MOZ and visibility
when a table was being sorted dynamically...

// Set the table display style to "none" - necessary for Netscape 6
// browsers.
var oldDsply = tblEl.style.display;
tblEl.style.display = "none";
....
// Restore the table's display style.
tblEl.style.display = oldDsply;

Maybe that will help?

--
 
D

Drunken pixel

Hi! I am (e-mail address removed)! Forgot to configure my news settings. Sorry!

I isolated the problem (see sample source code at end).
The funny thing is, that adding a line to the table works now.
But.... if the window is created (first call of test()) then the element
"here" can not be found. This seems to be a timing problem. Window not
completed yet? How can I synchronize this?

Greetings,
dp

-- begin: testwindow.html --
<html>
<head>
<title>TESTWINDOW</title>
<script>
var mywindow = null;
function test() {

if( null == mywindow ) {
mywindow = window.open( "local.html", "aName",
"width=400, height=400, left=10, top=10, location=false,"
+ "menubar=false, resizable=true, scrollbars=true,"
+ "status=false, toolbar=false" );
}

var here = mywindow.document.getElementById( "here" );

var tr = mywindow.document.createElement( "tr" );
var td = mywindow.document.createElement( "td" );
var txt = mywindow.document.createTextNode( "text" );

td.appendChild( txt );
tr.appendChild( td );

if( null != here ) {
here.parentNode.insertBefore( tr, here );
}
}
</script>
</head>
<body>
<table border="1">
<tr>
<td onclick="test(); return false;">test</td>
</tr>
</table>
</body>
</html>
-- end: testwindow.html --

-- begin: local.html --

<html>
<head>
<title>LOCAL</title>
<script>
</script>
</head>
<body>
<table>
<tr>
<td>begin</td>
</tr>
<tr id="here" >
<td>end</td>
</tr>
</table>
</body>
</html>

</html>
-- end: local.html --
 
K

kaeli

Hi! I am (e-mail address removed)! Forgot to configure my news settings. Sorry!

I isolated the problem (see sample source code at end).
The funny thing is, that adding a line to the table works now.
But.... if the window is created (first call of test()) then the element
"here" can not be found. This seems to be a timing problem. Window not
completed yet? How can I synchronize this?


I would suggest setTimeout, but if people are using different connection
speeds, this could be variable.

I'd suggest a loop, waiting until mywindow.document is defined (not the
element itself, in case something goes wrong and the page is 404 or
something), but I think in the right situation, something could go very,
very wrong with that and you'd get an infinite loop.

So, my suggestion is a setTimeout at 1 second intervals that checks for
mywindow.document, loops if it isn't defined, but only loops 30 times.
No doc should take more than 30 seconds to load, unless it's the result
of a big DB operation or something.

Perhaps someone knows how to make it wait with an onload...or maybe
there is a .loaded property?

--
--
~kaeli~
Not one shred of evidence supports the notion that life is
serious.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top