cloneNode is a method on the HtmlElement prototype chain, used to create a copy of the specified dom node. It accepts a Boolean parameter include_all. If include_all is set to true, the copy will have all the child nodes of the specified node.
However, the script tag is also a dom node, and cloneNode is still valid for it. It has been measured that various browsers (especially IE) have inconsistent execution results of cloneNode. The main phenomena are the following two:
IE, at least IE8 and below, when cloning a node, if the node contains a script node, the script content of the script node may be executed again.
For non-IE browsers, the script content of the script node contained in a cloneNode node will not be executed again.
I am very satisfied with the performance of browsers other than IE. Regarding the "possibility" of IE mentioned above, there are two situations:
If cloneNode is a script node, regardless of whether the node is Neither external link scripts nor embedded scripts will be executed again.
If you cloneNode another node, the embedded scripts contained under the node will not be executed, but the external link scripts contained will be executed again.
Here is a demo that reproduces the problem of cloneNode under IE.
Are you going to get dizzy after seeing this? The solution is very simple. No matter what browser it is, just remove all script tags under the target node before cloning Node. Because the script has already been executed, removing its tags will not have any impact, as follows: