473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

DOM with newly opened window

I'm trying to use the DOM to write in a popped up window, like so:

<html>
<head>
<title>Test</title>
</head>
<body>
<script type="text/javascript">
var aWin=open( '', '_blank', 'width='+640+',height='+480+', resizable=0,scrollbars=0' );
var fragment=aWin.document.createDocumentFragment();
var head=fragment.appendChild( document.createElement('head') );
var e=head.appendChild( document.createElement('script') );
e.text="alert('hello, world!')";
aWin.document.documentElement.appendChild( fragment );
</script></body></html>

Netscape 6 and FireFox seem to handle it just fine, but Opera does
nothing and IE6 complains about 'no such interface' on the
fragment.appendChild line (or crashes outright!). I presume I'm doing
something wrong, but I have no idea what... Any help would be
appreciated.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #1
2 1165
Christopher Benson-Manica <at***@nospam.cyberspace.org> spoke thus:
var fragment=aWin.document.createDocumentFragment();
var head=fragment.appendChild( document.createElement('head') );
var e=head.appendChild( document.createElement('script') );


So it turns out that I need aWin.document.createElement for this to
work. I'm curious, though - why doesn't IE let you add an element
you've created with one document to another document's tree? Is that
standard behavior, or is it a cruel M$ trick?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 23 '05 #2


Christopher Benson-Manica wrote:

So it turns out that I need aWin.document.createElement for this to
work. I'm curious, though - why doesn't IE let you add an element
you've created with one document to another document's tree? Is that
standard behavior, or is it a cruel M$ trick?


The W3C DOM standard in Level 2 has defined a method
var importedNode = document.importNode(nodeFromOtherDocument,
true/false);
// now insert e.g.
document.documentElement.appendChild(importedNode) ;
as the proper way to be able to prepare to insert a node from one
document into the other so the W3C DOM indeed expects that
implementations do not necessarily allow you to move nodes from one
document to the other.
Of course all IE DOM stuff is mostly grown before W3C DOM Level 2 became
a recommendation, it doesn't have importNode for instance even in IE 6.
Indeed if one looks closely at the W3C DOM Level 2 Core methods like
appendChild in
<http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1950641247>
then it says:
Exceptions: "WRONG_DOCUMENT_ERR: Raised if newChild was created from
a different document than the one that created this node."
so an implementation is even required to throw an exception if a node
from one document is inserted in another document.
I think Mozilla doesn't, Opera 7 for instance does.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #3

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

Similar topics

2
by: yootzee | last post by:
Greetings all, I'm having a problem with scrolling vertically in a newly created browser window. The vertical scrolling is to reach some anchor point within the new browser window. I'm...
0
by: Nonoy of Philippines | last post by:
Hello, guys... I'm just starting to develop web applications and I have this problem regarding Session objects At some parts of my application, I open modal dialog window which also opens...
3
by: datactrl | last post by:
Hi, all Is that possible I can assign an window object variable to an already opened window? With window.open(), we can get a window object from opened window. If a window has already opened, is...
2
by: Michael Lee | last post by:
Does anyone know why the following function works in FireFox but not in IE6? function ShowTable() { clonedNode = document.getElementById("myTable").cloneNode(true); win = window.open();...
6
by: Sujan | last post by:
Hello all, Help me! -------------------- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <script language="JavaScript"> <!--
1
by: John | last post by:
Hi, I'm having a problem opening / downloading csv files when called from a page opened with window.showModalDialog( ). To isolate this problem, I've written 3 files (see below). 1. main.htm...
2
by: John | last post by:
Hi, I posted this earlier in microsoft.public.dotnet.framework.aspnet, but didn't get a response, so I thought I'd try here. Basically, I'm having a problem opening / downloading csv files...
1
by: mcmwhite | last post by:
Hi, Does anyone know how I can open a newly-created HTML page in a new window, using ASP.NET? Eg. I have an ASP.NET page which creates some new HTML, based on what the user has entered into a...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.