This project is archived and is in readonly mode.

#225 ✓wontfix

Element::clone(true) clones and executes <script> tags on FF3

Reported by elado | July 15th, 2008 @ 03:35 PM | in 2.0 (closed)

The following code alerts twice on FF3, only once on IE7

I think it's best if Element::clone wouldn't clone scripts, I cannot think of a case when this is needed.

<script type="text/javascript">
window.addEvent("domready",function () {
<div id="x">
	<script type="text/javascript">
<div id="y"></div>

I've added

if (/script/i.test(this.childNodes[i].tagName)) continue;

to the clone method, which is now:

clone: function(contents, keepid){
	switch ($type(this)){
		case 'element':
			var attributes = {};
			for (var j = 0, l = this.attributes.length; j < l; j++){
				var attribute = this.attributes[j], key = attribute.nodeName.toLowerCase();
				if (Browser.Engine.trident && (/input/i).test(this.tagName) && (/width|height/).test(key)) continue;
				var value = (key == 'style' && ? : attribute.nodeValue;
				if (!$chk(value) || key == 'uid' || (key == 'id' && !keepid)) continue;
				if (value != 'inherit' && ['string', 'number'].contains($type(value))) attributes[key] = value;
			var element = new Element(this.nodeName.toLowerCase(), attributes);
			if (contents !== false){
				for (var i = 0, k = this.childNodes.length; i < k; i++){
					if (/script/i.test(this.childNodes[i].tagName)) continue;

					var child = Element.clone(this.childNodes[i], true, keepid);
					if (child) element.grab(child);
			return element;
		case 'textnode': return document.newTextNode(this.nodeValue);
	return null;


Comments and changes to this ticket

  • Jan Kassens

    Jan Kassens July 17th, 2008 @ 06:43 PM

    • State changed from “new” to “open”

    is ignoring child script tags in Element::clone the expected behaviour? What if you call scriptElement.clone()?

  • elado

    elado July 17th, 2008 @ 07:50 PM

    IMHO, I doubt script.clone is useful :)

    First, there's a difference between IE and FF. IE won't alert and FF will.

    Second, if you put document.write (event it's not standard nowadays, but hey, google analytics still uses it) it'll behave like document.write is being called after page is loaded (blanks the screen and writes the content).

    I encountered this thing when I used Sortables with clones and my items had some script elements. (That brings me a thought why won't I make those scripts totally unobtrusive, in external file but that's totally different story :) )

  • Christoph Pojer

    Christoph Pojer September 5th, 2010 @ 12:45 PM

    • State changed from “open” to “wontfix”
    • Milestone order changed from “0” to “0”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins