473,761 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot appendChild() to a newly opened window

Does anyone know why the following function works in FireFox but not in IE6?

function ShowTable()
{
clonedNode = document.getEle mentById("myTab le").cloneNode( true);
win = window.open();
win.document.bo dy.appendChild( clonedNode);
}

I am trying to display a table with id="myTable" in a new window. IE6
complains that "document.b ody" is null or not an object.

Thanks!

Michael Lee

Jul 23 '05 #1
2 8519


Michael Lee wrote:
Does anyone know why the following function works in FireFox but not in IE6?

function ShowTable()
{
clonedNode = document.getEle mentById("myTab le").cloneNode( true);
win = window.open();
win.document.bo dy.appendChild( clonedNode);
}


First window.open() doesn't load any document, and even if you used
window.open('wh atever.html')
the loading of the document would happen asynchronously and the next
line is executed without waiting for the document to load so directly
accessing
win.document.bo dy
is not going to work reliably and consistently.
Furthermore IE doesn't allow you to take nodes from one document and
insert them into another document. Nor does Opera. The W3C DOM suggests
to use importNode and Opera and Mozilla implement that. For IE you are
left with implementing that yourself or using innerHTML/outerHTML and/or
insertAdjacentH TML.
The solution to your window access is probably to load a page with
window.open that in its onload handler copies the table from the opener
window's document.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
While you may not be able to direclty append a node from one wndow to
the other, there is a work-around, which I've used in:
http://www.room535.org/news/
You can transfer a reference (or array of references) to the nodes in
window 1 to window 2, as follows.

------------------------------------------
In Window 1:

var toWin = top.opener;
toWin.getNodesF romWindow_1(nod e_arry);

------------------------------------------------------------

In Window 2:
What you do in Window 2 will depend on what you want to do with the
node, but this is a stripped down idea of what's involved. The
function cloneExternalNo de(n,parent) is key to the transfer; it
creates a new node from the node reference obtained from Window 1 and
then you can do what you want with it.

var mainDiv; //needs to be defined
getNodesFromWin dow_1(nodes) {
for(var i=0; i < nodes.length; i++) {
// pass parent, if exits or else null
var clone = cloneExternalNo de(n,parent);
mainDiv.appendC hild(clone);
}
}

function cloneExternalNo de(n,parent)
{
if(n.nodeType == 3) {
var newNode = document.create TextNode(n.data );
}
else {
var newNode = document.create Element(n.nodeN ame);
var att = n.attributes;
setcloneAttribu tes(newNode, att);
}
if(parent) parent.appendCh ild(newNode);

var children = n.childNodes;
for(var j=0; j<children.leng th; j++) {
cloneExternalNo de(children[j], newNode);
}

return newNode;
}

On Fri, 02 Jul 2004 19:49:25 +0200, Martin Honnen <ma*******@yaho o.de>
wrote:


Michael Lee wrote:
Does anyone know why the following function works in FireFox but not in IE6?

function ShowTable()
{
clonedNode = document.getEle mentById("myTab le").cloneNode( true);
win = window.open();
win.document.bo dy.appendChild( clonedNode);
}


First window.open() doesn't load any document, and even if you used
window.open('wh atever.html')
the loading of the document would happen asynchronously and the next
line is executed without waiting for the document to load so directly
accessing
win.document.bo dy
is not going to work reliably and consistently.
Furthermore IE doesn't allow you to take nodes from one document and
insert them into another document. Nor does Opera. The W3C DOM suggests
to use importNode and Opera and Mozilla implement that. For IE you are
left with implementing that yourself or using innerHTML/outerHTML and/or
insertAdjacent HTML.
The solution to your window access is probably to load a page with
window.open that in its onload handler copies the table from the opener
window's document.
--

Martin Honnen
http://JavaScript.FAQTs.com/


Myron Turner
www.room535.org
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3353
by: Matt | last post by:
My problem is when the user click the submit button, it will launch another new window for the request page. I want to confirm we cannot use JavaScript open window functions to open a request page? The following page2.asp won't output the value entered in page1.asp. However, if we do <form action="page2.asp" method="get" target="_blank">, then it will open a new window for the request page, instead of using the same window as page1.asp....
3
1379
by: user | last post by:
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>
1
8405
by: NeilL | last post by:
I'm trying to create an XML document that can be opened in Excel. I have some simple code that ... eventually does the following elem = _doc.CreateElement("Style"); elem.SetAttribute("ss:ID","Default"); elem.SetAttribute("ss:Name","Normal"); parentElem.AppendChild(elem); to add a "Style" item with 2 attributes. My problem is that when I do a Save on the XML document I get an Attribute exception "Cannot use a prefix
3
4155
by: Glenn Davy | last post by:
Q. How can I 'see' the number of table id's access is using for tracking recordsets? Details: I have some ado code that itterates through a recordset and calls a procedure on each record. This procedure calls a hierachy of other subs/functions etc which _do_ instantiate several custom objects (class modules), recordsets, both ado and dao at different times. Eventually the code breaks with the error number -2147467259, (though has also...
0
2961
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode thread. so far so good. all contacts r added properly. now when another login adds me in his contact, i recv a subscription, so i popup a form and ask for accept/reject. this all happens in a separate thread. popup form gets opened and choice is...
4
2365
by: joecap5 | last post by:
I have a main window and a menu window. The menu window is opened from the main window by clicking on "Open Menu". A google window can also be opened from the main window by clicking "Open Google". If "google_win" is clicked on in the menu window the google window is focused on. Now if "Add Google to Menu" is clicked in the main window, another line is written to the menu window also saying "google_win". This second "google_win" is added...
7
3357
by: dennis.sprengers | last post by:
I am trying to write an editor object, which adds some functionality and a toolbar to every textarea with a "form-textarea" class. Both FF and IE generate an error in line 20 (container.appendChild(this.toolbar);) saying "Node cannot be inserted at the specified point in the hierarchy" code: "3" I have two questions: - who would help me with this error - please provide other feedback about my code, since I want to write a solid...
4
1876
by: =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post by:
Was editing code, am getting the following errors } expected Type or namespace definition, or end-of-file expected Eyes crossed cannot find code below! using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
2
3772
by: GuruPrasadBytes | last post by:
I am opened window.open(child.aspx page) from the parent.aspx file the below code is from parent.aspx, <HTML> <HEAD> ...... </HEAD> <body onload="loadXML();"> ..... <input id="AddSecurityBtn" type="button" runat="server" onclick='javascript: Args = objDoc.selectSingleNode('//Books'); Args = buildBookTable ; Args =null; window.open('child.aspx','800','900');' value="Add Books" />
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8814
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.