[Javascript] Firefox: Script removed by snapshot save (when saving generated html page)

Mike Dougherty mdougherty at pbp.com
Sat Oct 23 11:55:33 CDT 2010


On Tue, Oct 12, 2010 at 10:00 AM, Alberto Domingo <alberto.domingo at uah.es>wrote:

> var t = "";
> t += "<HTML>\r";
> t += "<HEAD>\r";
> t += "<TITLE>";
> t += "GENERATED PAGE";
> t += "</TITLE>\r";
> t += "<scr"+"ipt type='text/javascript' src='somescript.js'>\r";
> t += "</scr"+"ipt>\r";
> t += "<scr"+"ipt type='text/javascript'>\r";
> t += "var a = 1;";
> t += "</scr"+"ipt>\r";
> t += "</HEAD>\r";
> t += "<BODY>\r";
> t += "Save this page and look at the saved code. Also in the associated
> folder, look at the scripts."
> t += "<scr"+"ipt type='text/javascript' src='otherscript.js'>\r";
> t += "</scr"+"ipt>\r";
> t += "</BODY>\r";
> t += "</HTML>\r";
>

I don't understand why people use this pattern.  Why not reduce all those +=
to a single assignment:
var t = "<html>"
+ "<head>"
+ "<title>
+ .... etc.

Or if you really need granular/line-by-line string building (loop iteration,
complex flow)
var a = [];
a.push( "<html>" );
a.push( etc );
var t = a.join("");  /* or a.join("\r") if you really want the line breaks
in source */


More information about the Javascript mailing list