<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: The problem with innerHTML</title>
	<atom:link href="http://ajaxian.com/archives/the-problem-with-innerhtml/feed" rel="self" type="application/rss+xml" />
	<link>http://ajaxian.com/archives/the-problem-with-innerhtml</link>
	<description>Cleaning up the web with Ajax</description>
	<lastBuildDate>Thu, 17 May 2012 07:43:39 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Morgan Roderick</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260095</link>
		<dc:creator>Morgan Roderick</dc:creator>
		<pubDate>Tue, 18 Dec 2007 09:29:55 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260095</guid>
		<description>kschneid: that&#039;s the one. That article inspired me greatly awhile back, and has caused a small shift in how I write my javascript :-)</description>
		<content:encoded><![CDATA[<p>kschneid: that&#8217;s the one. That article inspired me greatly awhile back, and has caused a small shift in how I write my javascript :-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MiguelVentura</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260039</link>
		<dc:creator>MiguelVentura</dc:creator>
		<pubDate>Sun, 16 Dec 2007 22:51:01 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260039</guid>
		<description>Sorry for my previous post... I was hoping to get &quot;readable version here.</description>
		<content:encoded><![CDATA[<p>Sorry for my previous post&#8230; I was hoping to get &#8220;readable version here.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MiguelVentura</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260038</link>
		<dc:creator>MiguelVentura</dc:creator>
		<pubDate>Sun, 16 Dec 2007 22:35:15 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260038</guid>
		<description>I personaly never liked using regular expressions to filter HTML. Unless you use a grammar you won&#039;t really be able to parse anything.
    el.innerHTML = html.replace(/]*&gt;((.&#124;[\r\n])*?)/ig, &quot;&quot;);
looks good, but what if instead of terminating the script with &quot;&quot; I terminate it with &quot;&quot; ? Or better yet, how about
html = &quot;void(0);pt defer=\&quot;true\&quot;&gt;alert(&#039;foo&#039;);&quot;

If this is about security and disabling script injection attacks, it still has a lot that isn&#039;t done.</description>
		<content:encoded><![CDATA[<p>I personaly never liked using regular expressions to filter HTML. Unless you use a grammar you won&#8217;t really be able to parse anything.<br />
    el.innerHTML = html.replace(/]*&gt;((.|[\r\n])*?)/ig, &#8220;&#8221;);<br />
looks good, but what if instead of terminating the script with &#8220;&#8221; I terminate it with &#8220;&#8221; ? Or better yet, how about<br />
html = &#8220;void(0);pt defer=\&#8221;true\&#8221;&gt;alert(&#8216;foo&#8217;);&#8221;</p>
<p>If this is about security and disabling script injection attacks, it still has a lot that isn&#8217;t done.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Schill</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260025</link>
		<dc:creator>Schill</dc:creator>
		<pubDate>Sat, 15 Dec 2007 21:17:39 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260025</guid>
		<description>Actually, interestingly enough, I&#039;ve noted that you can write to innerHTML in at least a limited fashion with Firefox 2/3 and Safari 3 in this case; my personal site is served with the correct MIME type when applicable, and I am (unfortunately) writing to innerHTML in a few spots. I was thinking I&#039;d have to rewrite those bits to use proper DOM calls, but it turns out I was able to get away with a few things. This was not the case in 2004 when &lt;a href=&quot;http://www.schillmania.com/content/entries/2004/10/24/application-xhtml+xml/&quot; rel=&quot;nofollow&quot;&gt;I was &quot;researching&quot; application/xhtml+xml&lt;/a&gt;, Firefox would throw errors when any innerHTML &quot;write&quot; call was attempted. I get the feeling they decided to allow some form of writes because the technique is used (and overly-so, in my opinion,) so often.</description>
		<content:encoded><![CDATA[<p>Actually, interestingly enough, I&#8217;ve noted that you can write to innerHTML in at least a limited fashion with Firefox 2/3 and Safari 3 in this case; my personal site is served with the correct MIME type when applicable, and I am (unfortunately) writing to innerHTML in a few spots. I was thinking I&#8217;d have to rewrite those bits to use proper DOM calls, but it turns out I was able to get away with a few things. This was not the case in 2004 when <a href="http://www.schillmania.com/content/entries/2004/10/24/application-xhtml+xml/" rel="nofollow">I was &#8220;researching&#8221; application/xhtml+xml</a>, Firefox would throw errors when any innerHTML &#8220;write&#8221; call was attempted. I get the feeling they decided to allow some form of writes because the technique is used (and overly-so, in my opinion,) so often.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: posaune</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260018</link>
		<dc:creator>posaune</dc:creator>
		<pubDate>Sat, 15 Dec 2007 06:07:18 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260018</guid>
		<description>One thing concerning innerHTML that never seems to be mentioned is that it will not work when content is served as application/xhtml+xml (or any other flavor of true xml for that matter)</description>
		<content:encoded><![CDATA[<p>One thing concerning innerHTML that never seems to be mentioned is that it will not work when content is served as application/xhtml+xml (or any other flavor of true xml for that matter)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: HudsonTavares</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260012</link>
		<dc:creator>HudsonTavares</dc:creator>
		<pubDate>Sat, 15 Dec 2007 02:15:55 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260012</guid>
		<description>* &lt;i&gt;Setting innerHTML will destroy existing HTML elements that have event handlers attached to them, potentially creating a memory leak on some browsers.&lt;/i&gt;

That&#039;s a implementation problem, and not an argument, neither in a favorably or contrary way to innerHTML.

* &lt;i&gt;You canâ€™t set the innerHTML property on all HTML elements on all browsers (for instance, Internet Explorer wonâ€™t let you set the innerHTML property of a table row element)&lt;/i&gt;

Until IE isn&#039;t dead, cross-browser solutions still as a set of work around. Ok, it&#039;s a good argument, but... we all know that there are millions of further things which IE doesn&#039;t allow. We&#039;re furious, however, not amazed about.

@Schill
When using AJAX, sometimes i throw the results on a XSLT processor before be attached on the response. So, i use innerHTML without merging the layers of my applications, pasting directly the XSLT results on a target node.</description>
		<content:encoded><![CDATA[<p>* <i>Setting innerHTML will destroy existing HTML elements that have event handlers attached to them, potentially creating a memory leak on some browsers.</i></p>
<p>That&#8217;s a implementation problem, and not an argument, neither in a favorably or contrary way to innerHTML.</p>
<p>* <i>You canâ€™t set the innerHTML property on all HTML elements on all browsers (for instance, Internet Explorer wonâ€™t let you set the innerHTML property of a table row element)</i></p>
<p>Until IE isn&#8217;t dead, cross-browser solutions still as a set of work around. Ok, it&#8217;s a good argument, but&#8230; we all know that there are millions of further things which IE doesn&#8217;t allow. We&#8217;re furious, however, not amazed about.</p>
<p>@Schill<br />
When using AJAX, sometimes i throw the results on a XSLT processor before be attached on the response. So, i use innerHTML without merging the layers of my applications, pasting directly the XSLT results on a target node.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Schill</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260009</link>
		<dc:creator>Schill</dc:creator>
		<pubDate>Fri, 14 Dec 2007 23:22:29 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260009</guid>
		<description>In my experience, if you build a DOM structure offline (createDocumentFragment/createElement and so on,) finally inserting to the &quot;live&quot; document with a single appendChild() call, the browser shouldn&#039;t have to do any more reflow work than if innerHTML were used.
&#160;
I&#039;m also a fan of having &quot;templates&quot; in HTML wherever possible (avoiding creating HTML using JS is always good, thus separating layers etc.), cloning that template, modifying and appending to the DOM. Again if you do all of this work offline and append to the live document once, I think the performance is pretty solid.</description>
		<content:encoded><![CDATA[<p>In my experience, if you build a DOM structure offline (createDocumentFragment/createElement and so on,) finally inserting to the &#8220;live&#8221; document with a single appendChild() call, the browser shouldn&#8217;t have to do any more reflow work than if innerHTML were used.<br />
&nbsp;<br />
I&#8217;m also a fan of having &#8220;templates&#8221; in HTML wherever possible (avoiding creating HTML using JS is always good, thus separating layers etc.), cloning that template, modifying and appending to the DOM. Again if you do all of this work offline and append to the live document once, I think the performance is pretty solid.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260004</link>
		<dc:creator>Ryan</dc:creator>
		<pubDate>Fri, 14 Dec 2007 19:54:25 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260004</guid>
		<description>The Taconite Ajax framework does not use the innerHTML property**, instead relying on DOM manipulation methods.  All you do is specify the markup you want, *as markup*, and Taconite does the renderning for you.

Ryan
Taconite Lead Developer

** The innerHTML property is used in a few spots to try to overcome some IE quirks, but it is used quite sparingly.</description>
		<content:encoded><![CDATA[<p>The Taconite Ajax framework does not use the innerHTML property**, instead relying on DOM manipulation methods.  All you do is specify the markup you want, *as markup*, and Taconite does the renderning for you.</p>
<p>Ryan<br />
Taconite Lead Developer</p>
<p>** The innerHTML property is used in a few spots to try to overcome some IE quirks, but it is used quite sparingly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: skypoet</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-260000</link>
		<dc:creator>skypoet</dc:creator>
		<pubDate>Fri, 14 Dec 2007 17:26:58 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-260000</guid>
		<description>Julien, 

Thanks for the article.  I&#039;m also glad that you brought up the fact that innerHTML is extremely fast!

Oliver</description>
		<content:encoded><![CDATA[<p>Julien, </p>
<p>Thanks for the article.  I&#8217;m also glad that you brought up the fact that innerHTML is extremely fast!</p>
<p>Oliver</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlecomte</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259996</link>
		<dc:creator>jlecomte</dc:creator>
		<pubDate>Fri, 14 Dec 2007 16:36:34 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259996</guid>
		<description>@mdmadph

One of the best use case for the &lt;code&gt;innerHTML&lt;/code&gt; property is when it comes to modifying the document tree efficiently. Using &lt;code&gt;innerHTML&lt;/code&gt; is a lot faster than using the DOM APIs.</description>
		<content:encoded><![CDATA[<p>@mdmadph</p>
<p>One of the best use case for the <code>innerHTML</code> property is when it comes to modifying the document tree efficiently. Using <code>innerHTML</code> is a lot faster than using the DOM APIs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259995</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Fri, 14 Dec 2007 16:27:12 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259995</guid>
		<description>sometimes innerHTML is only the right way
http://www.quirksmode.org/dom/innerhtml.html</description>
		<content:encoded><![CDATA[<p>sometimes innerHTML is only the right way<br />
<a href="http://www.quirksmode.org/dom/innerhtml.html" rel="nofollow">http://www.quirksmode.org/dom/innerhtml.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jlecomte</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259991</link>
		<dc:creator>jlecomte</dc:creator>
		<pubDate>Fri, 14 Dec 2007 15:42:21 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259991</guid>
		<description>@Mathieu

I could not agree more. The &lt;code&gt;setInnerHTML&lt;/code&gt; function barely normalizes the script tag execution behavior across all A-grade browsers.

@Morgan

Reducing the number of event handlers definitely helps alleviating some of the associated memory leaks, and event delegation is a well-known pattern that helps doing just that.</description>
		<content:encoded><![CDATA[<p>@Mathieu</p>
<p>I could not agree more. The <code>setInnerHTML</code> function barely normalizes the script tag execution behavior across all A-grade browsers.</p>
<p>@Morgan</p>
<p>Reducing the number of event handlers definitely helps alleviating some of the associated memory leaks, and event delegation is a well-known pattern that helps doing just that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pete B</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259986</link>
		<dc:creator>Pete B</dc:creator>
		<pubDate>Fri, 14 Dec 2007 14:23:15 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259986</guid>
		<description>I&#039;ve run up against a number of problems using innerHTML recently: document.body.innerHTML += &#039;your stuff&#039; seems to break the DOM tree so that any node collections and event handlers are lost. Also, when using innerHTML to parse a json feed (in a form - asp.net) makes ie randomly crash</description>
		<content:encoded><![CDATA[<p>I&#8217;ve run up against a number of problems using innerHTML recently: document.body.innerHTML += &#8216;your stuff&#8217; seems to break the DOM tree so that any node collections and event handlers are lost. Also, when using innerHTML to parse a json feed (in a form &#8211; asp.net) makes ie randomly crash</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Morgan Roderick</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259982</link>
		<dc:creator>Morgan Roderick</dc:creator>
		<pubDate>Fri, 14 Dec 2007 13:54:11 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259982</guid>
		<description>Some of the issues with event listeners and innerHTML can easily be overcome.

Chris Heilmann (unless my memory fails me) wrote an excellent article on using event delegates instead of event handlers in javascript. Chris: can you link it?

LowPro for Prototype, by Dan Webb, has the brilliant Event.addBehavior method, that also overcomes problems with dom updates and event handlers.</description>
		<content:encoded><![CDATA[<p>Some of the issues with event listeners and innerHTML can easily be overcome.</p>
<p>Chris Heilmann (unless my memory fails me) wrote an excellent article on using event delegates instead of event handlers in javascript. Chris: can you link it?</p>
<p>LowPro for Prototype, by Dan Webb, has the brilliant Event.addBehavior method, that also overcomes problems with dom updates and event handlers.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Site Smart</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259980</link>
		<dc:creator>Site Smart</dc:creator>
		<pubDate>Fri, 14 Dec 2007 13:36:43 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259980</guid>
		<description>since DOM is the recommendation it really shouldn&#039;t be an issue</description>
		<content:encoded><![CDATA[<p>since DOM is the recommendation it really shouldn&#8217;t be an issue</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Snowcore</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259976</link>
		<dc:creator>Snowcore</dc:creator>
		<pubDate>Fri, 14 Dec 2007 13:08:53 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259976</guid>
		<description>Concerning innerHTML of the  in IE it&#039;s a real problem.
My solution is to receive data via AJAX, and then use DOM functions to build new rows of the table: 

 document.createElement(&quot;TR&quot;);
 // ....

 etc.</description>
		<content:encoded><![CDATA[<p>Concerning innerHTML of the  in IE it&#8217;s a real problem.<br />
My solution is to receive data via AJAX, and then use DOM functions to build new rows of the table: </p>
<p> document.createElement(&#8220;TR&#8221;);<br />
 // &#8230;.</p>
<p> etc.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rodrigo</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259975</link>
		<dc:creator>Rodrigo</dc:creator>
		<pubDate>Fri, 14 Dec 2007 13:05:50 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259975</guid>
		<description>Using innerHMTL also has the problem of getting an &quot;Unknow runtime error&quot; in Internet Explorer sometimes.</description>
		<content:encoded><![CDATA[<p>Using innerHMTL also has the problem of getting an &#8220;Unknow runtime error&#8221; in Internet Explorer sometimes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathieu \'p01\' Henri</title>
		<link>http://ajaxian.com/archives/the-problem-with-innerhtml/comment-page-1#comment-259971</link>
		<dc:creator>Mathieu \'p01\' Henri</dc:creator>
		<pubDate>Fri, 14 Dec 2007 12:50:51 +0000</pubDate>
		<guid isPermaLink="false">http://ajaxian.com/?p=3115#comment-259971</guid>
		<description>Script tags are just one out of many ways to inject malicious code. Stripping only the script tag is sub par. You must also be careful of IFRAMEs, OBJECT, EMBED, IMG ... and even some attributes ( some browsers still allow script execution in &lt;em&gt;style=&quot;background:url(javascript:...);&quot;&lt;/em&gt;.

The only way to sanitize properly markup to be injected is to use a whitelist of tags and attributes ... or to simply not inject markup using innerHTML.</description>
		<content:encoded><![CDATA[<p>Script tags are just one out of many ways to inject malicious code. Stripping only the script tag is sub par. You must also be careful of IFRAMEs, OBJECT, EMBED, IMG &#8230; and even some attributes ( some browsers still allow script execution in <em>style=&#8221;background:url(javascript:&#8230;);&#8221;</em>.</p>
<p>The only way to sanitize properly markup to be injected is to use a whitelist of tags and attributes &#8230; or to simply not inject markup using innerHTML.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

