Closed
Bug 383983
Opened 18 years ago
Closed 6 years ago
window.open returns HTMLDocument instead of SVGDocument
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: cfcohen77, Unassigned)
References
(Depends on 1 open bug)
Details
(Keywords: dev-doc-needed)
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
This looks like a bug to me, but
Reproducible: Always
Steps to Reproduce:
test.html
----8<--------8<--------8<--------8<--------8<----
<html><script>
function init() {
var win = window.open('test.svg', '', '');
alert(win.document);
var myrect = win.document.createElementNS("http://www.w3.org/2000/svg", "rect");
win.document.appendChild(myrect);
}
</script>
<body onLoad="init()"></body>
</html>
----8<--------8<--------8<--------8<--------8<----
test.svg
----8<--------8<--------8<--------8<--------8<----
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" width="100" height="100" fill="red"/>
</svg>
----8<--------8<--------8<--------8<--------8<----
Actual Results:
The alert displays "[object HTMLDocument]". Subsequent attempts to use the document produces errors like:
Error: uncaught exception: [Exception... "Node cannot be inserted at the specified point in the hierarchy" code: "3" nsresult: "0x80530003 (NS_ERROR_DOM_HIERARCHY_REQUEST_ERR)" location: "file:///C:test.html Line: 8"]
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMHTMLHtmlElement.appendChild]" nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)" location: "JS frame :: chrome://xxx/test.xul :: init :: line 38" data: no]
Expected Results:
I would expect win.document to have a document of type of SVGDocument, and display "[object SVGDocument]".
If this is somehow expected behavior, sorry for the bogus bug report, but this appears to be broken to me...
Reporter | ||
Comment 1•18 years ago
|
||
If I wait a while, the correct result is returned. It looks like simply getting out of the onLoad event is enough. Changing the code to:
var win;
function init() {
win = window.open('test.svg', '', '');
setTimeout("later()", 1);
}
function later() {
alert(win.document);
}
correctly alerts "[object SVGDocument]". This seems very hackish, and strongly suggests to me that this behavior is indeed a bug. On the other hand, now that I see that the problem is clearly an ordering issue, and that the window.open doesn't occur until after the onLoad event exits, I suppose it's possible that nothing can be done to correct it.
Is there anywhere that all this fine print gets recorded? I sometimes find it nearly impossible to code using Javascript and the DOM because functions do _NOT_ behave exactly as documented, but rather that way most of the time. This routinely leaves me figuring out _why_ it doesn't do what it says it will. :-(
Comment 2•18 years ago
|
||
There is much of DOM and DOM:Events changes on trunk. What happens if you try your code against trunk?
Updated•9 years ago
|
Keywords: dev-doc-needed
Assignee | ||
Updated•6 years ago
|
Component: DOM → DOM: Core & HTML
![]() |
||
Comment 3•6 years ago
|
||
When window.open() is initially called it creates an about:blank document (which is HTML). The SVG document doesn't exist until the server response for the 'test.svg' URL comes back, which can't happen synchronously.
This is all specified in the HTML spec (which defines window.open) at this point.
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•