W3C home > Mailing lists > Public > public-html@w3.org > January 2009

Re: cloneNode() and script execution

From: Andrew Fedoniouk <news@terrainformatica.com>
Date: Sat, 17 Jan 2009 21:02:31 -0800
Message-ID: <4972B7E7.3020909@terrainformatica.com>
To: "Hallvord R. M. Steen" <hallvord@opera.com>
CC: public-html@w3.org

Hallvord R. M. Steen wrote:
> 
> Here is another issue for Ian to ponder while working on the script 
> execution stuff:
> 
> If you clone a script node and append the to the document, does it run?
> 
> Browsers differ:
> 
> cloneNode(true) - Opera no, Firefox no, Safari yes, IE fails
> cloneNode(false) - Opera yes, Firefox no, Safari yes, IE fails
> 
>  From my naturally biased point of view I think Opera makes more sense - 
> a "deep" clone remembers that the script was already executed, a shallow 
> doesn't because it doesn't clone the script code. I think any use cases 
> one might think of for re-executing script clones are already much 
> better handled by putting the code inside a function and doing a simple 
> function call.
> 

It is not so wise idea to run scripts while cloning nodes.
Consider this:

<div id="self">
   ...something...
   <script>
     var s = document.getDocumentById("self").cloneNode();
     document.body.appendNode(s);
   </script>
</div>

It is quite easy to get into this trap.

-- 
Andrew Fedoniouk.

http://terrainformatica.com
Received on Sunday, 18 January 2009 05:02:35 UTC

This archive was generated by hypermail 2.3.1 : Monday, 29 September 2014 09:39:00 UTC