Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-14-2004, 10:03 AM   PM User | #1
swmr
Regular Coder

 
Join Date: Feb 2003
Posts: 638
Thanks: 0
Thanked 0 Times in 0 Posts
swmr is an unknown quantity at this point
createDocumentFragment:

Under what circumstances would there be an advantage to using this object in an html document?
__________________
hmm... ?
swmr is offline   Reply With Quote
Old 02-14-2004, 01:49 PM   PM User | #2
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
There is one large benefit to it - when you assign a DocumentFragment to another Node, the children of the DocumentFragment are assigned to the Node instead of the actual DocumentFragement. That means that you can assign multiple children at the same time instead of assigning them one at a time.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 02-15-2004, 03:14 AM   PM User | #3
swmr
Regular Coder

 
Join Date: Feb 2003
Posts: 638
Thanks: 0
Thanked 0 Times in 0 Posts
swmr is an unknown quantity at this point
Oh, that makes sense.

Have you seen this being put to practical use anywhere?
__________________
hmm... ?
swmr is offline   Reply With Quote
Old 02-15-2004, 10:54 AM   PM User | #4
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
IIRC only Mozilla supports DocumentFragment for the moment, so it's kinda limited for the moment.
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 02-15-2004, 11:54 AM   PM User | #5
swmr
Regular Coder

 
Join Date: Feb 2003
Posts: 638
Thanks: 0
Thanked 0 Times in 0 Posts
swmr is an unknown quantity at this point
It is also featured in IE6: About the W3C Document Object Model

edit >> Actually its listed as available from IE5+

Win16: 5
Win32: 5
Unix: 5
Mac: 5
Windows CE: 5.5
__________________
hmm... ?

Last edited by swmr; 02-15-2004 at 12:22 PM..
swmr is offline   Reply With Quote
Old 02-18-2004, 06:47 AM   PM User | #6
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
Yeah but check this: if you use cloneNode(true) to copy a node from an <object>-embedded HTML document, what you get back is not a node at all - it's a document fragment with your node as its first child. Since it's in a document fragment you can't append it using appendNode, or move it with insertAdjacentElement or insertBefore - you have to copy it with outerHTML.

Stupid browser..
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

Last edited by brothercake; 02-18-2004 at 06:52 AM..
brothercake is offline   Reply With Quote
Old 02-18-2004, 07:20 AM   PM User | #7
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
James - is that really the problem? How about trying to use Document.importNode first, and then trying to append it?
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 02-18-2004, 08:22 PM   PM User | #8
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
importNode doesn't work in IE - cloneNode is the only way to copy a node afaik.

It might be related the strangeness of accessing the document in the first place - IE has contentWindow.document when it's an iframe, but an <object> has no contentWindow, and IE doesn't support contentDocument, so the only way I could find to get the document is with a reference to the <object> itself. Like this example, trying to copy individual <ul> nodes out of another element in the embedded document:
Code:
var obj = document.getElementById("someObject");
var doc = obj;
var docElement = doc.getElementById("whatever");
var docTree = docElement.getElementsByTagName('ul')[0];
var docUL = docTree.cloneNode(true)
Then query the parentNode of docTree - it's a document fragment; try to append or move the docTree node - you can't, because it isn't really a node.
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
brothercake is offline   Reply With Quote
Old 02-18-2004, 08:38 PM   PM User | #9
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
Oh, ie quirkyness again. I was thinking that this was rather another problem: Nodes belong to a document. You can't use a node from one document in another without importing it.

But then I never counted on iew being standards compliant...

How about using Element.ownerDocument on an element in the object document?
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 02-19-2004, 01:11 AM   PM User | #10
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
With liorean's help, we debugged this particular issue - instead of using the reference to the object, using the object property of the object returns a #document node:
Code:
var doc = obj.object;
But it still doesn't work, because I was using cloneNode instead of importNode - the ownerDocument of the cloned node is the <object> document, so it can't be appended to the outer document, because of the cross-document security restriction. Since importNode isn't supported in win/ie, outerHTML remains the only solution (or using an iframe instead of an object)

Sorry this is all a bit OT though ...
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

Last edited by brothercake; 02-19-2004 at 01:14 AM..
brothercake is offline   Reply With Quote
Old 03-26-2004, 05:57 PM   PM User | #11
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
James: About importNode, have you seen this? <http://neo.dzygn.com/archives/individual/56>
__________________
liorean <[lio@wg]>
Articles: RegEx evolt wsabstract , Named Arguments
Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards
liorean is offline   Reply With Quote
Old 03-26-2004, 10:33 PM   PM User | #12
brothercake
Senior Coder


 
Join Date: Jun 2002
Location: near Oswestry
Posts: 4,508
Thanks: 0
Thanked 0 Times in 0 Posts
brothercake is an unknown quantity at this point
Interesting. .. more round about than what I did, but undoubtedly more elegant.
__________________
"Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark
brothercake is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:39 PM.


Advertisement
Log in to turn off these ads.