Bug 594989 - injected <script> from snippets is not run. r+a=gavin
authorMarco Bonardo <mbonardo@mozilla.com>
Sat, 11 Sep 2010 09:45:11 +0200
changeset 52459 c7987be5466390327c6faa5e1771bed24a9ac605
parent 52458 3e24e4a0c2b5a371c2810fadc19649d891ee59ff
child 52461 cc4df3b40018d32f2566ae6a9e7b6ad3200f7b9d
push id15648
push usermak77@bonardo.net
push dateSat, 11 Sep 2010 07:45:51 +0000
treeherdermozilla-central@c7987be54663 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs594989
milestone2.0b6pre
first release with
nightly win64
c7987be54663 / 4.0b6pre / 20100911010228 / files
nightly linux32
nightly linux64
nightly mac
nightly win32
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly win64
Bug 594989 - injected <script> from snippets is not run. r+a=gavin
browser/base/content/aboutHome.js
--- a/browser/base/content/aboutHome.js
+++ b/browser/base/content/aboutHome.js
@@ -161,16 +161,24 @@ function loadSnippets()
 }
 
 function showSnippets()
 {
   let snippets = localStorage["snippets"];
   if (snippets) {
     let snippetsElt = document.getElementById("snippets");
     snippetsElt.innerHTML = snippets;
+    // Scripts injected by innerHTML are inactive, so we have to relocate them
+    // through DOM manipulation to activate their contents.
+    Array.forEach(snippetsElt.getElementsByTagName("script"), function(elt) {
+      let relocatedScript = document.createElement("script");
+      relocatedScript.type = "text/javascript;version=1.8";
+      relocatedScript.text = elt.text;
+      snippetsElt.replaceChild(relocatedScript, elt);
+    });
     snippetsElt.hidden = false;
   } else {
     // If there are no saved snippets, show one of the default ones.
     let defaultSnippetsElt = document.getElementById("defaultSnippets");
     let entries = defaultSnippetsElt.querySelectorAll("span");
     // Choose a random snippet.  Assume there is always at least one.
     let randIndex = Math.round(Math.random() * (entries.length - 1));
     let entry = entries[randIndex];