<?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: Cleanest way of executing javascript code on page load</title>
	<atom:link href="http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/</link>
	<description>Advanced katas for javascripters</description>
	<lastBuildDate>Fri, 30 Jul 2010 18:10:52 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: anthony</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-764</link>
		<dc:creator>anthony</dc:creator>
		<pubDate>Tue, 30 Jun 2009 06:12:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-764</guid>
		<description>Creating a custom EPiServer property is relatively easy - although I think I&#039;ve not quite got the hang of how to store the actual data. It must be converted to a string for storage in the database. I started to use an XmlSerializer but got confused (mainly as the JavaScript was doing my head in) as to where i should be doing the serialisation. Sadly the only example i could find on the net was how to create a custom property that was a string - about as much use as a chocolate fire guard! So here&#039;s my way of doing it - using a comma separated string (dirty I know!) - please feel free to show me the correct way.
http://www.casinoszocken.de/</description>
		<content:encoded><![CDATA[<p>Creating a custom EPiServer property is relatively easy &#8211; although I think I&#8217;ve not quite got the hang of how to store the actual data. It must be converted to a string for storage in the database. I started to use an XmlSerializer but got confused (mainly as the JavaScript was doing my head in) as to where i should be doing the serialisation. Sadly the only example i could find on the net was how to create a custom property that was a string &#8211; about as much use as a chocolate fire guard! So here&#8217;s my way of doing it &#8211; using a comma separated string (dirty I know!) &#8211; please feel free to show me the correct way.<br />
<a href="http://www.casinoszocken.de/" rel="nofollow">http://www.casinoszocken.de/</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trygve Lie</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-761</link>
		<dc:creator>Trygve Lie</dc:creator>
		<pubDate>Thu, 11 Jun 2009 23:46:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-761</guid>
		<description>Interesting. I&#039;ve been dealing with the same issue in a project which interac heavy with the DOM. I&#039;ve got some limitations in this project which prevents me from using any of the JS libraries out there (so the &quot;ready&quot; function in JQuery are out of the question) and easy injection into a document is a must.

I ended up writing a small bootstrap script for javascript functions.

The bootstrap has a array intended to hold functions. Then there is a small &quot;load&quot; function which attach itself to &quot;DOM readyness&quot; and run trought the array of functions and fire the functions in it&#039;s order in the array when the DOM is ready. For the &quot;DOM readyness&quot; detection I use the DOMContentLoaded which are supported in most new sane browsers and a small &quot;hack&quot; (http://javascript.nwbox.com/IEContentLoaded/) for detecting the same &quot;DOM readyness&quot; in IE. This way of detecting &quot;DOM readyness&quot; is pretty much the same way as JQuery and other JS libraries do.

I did post the bootstrap script with documentation, examples and the source a couple of weeks ago: http://www.trygve-lie.com/blog/entry/bootstraping_javascript</description>
		<content:encoded><![CDATA[<p>Interesting. I&#8217;ve been dealing with the same issue in a project which interac heavy with the DOM. I&#8217;ve got some limitations in this project which prevents me from using any of the JS libraries out there (so the &#8220;ready&#8221; function in JQuery are out of the question) and easy injection into a document is a must.</p>
<p>I ended up writing a small bootstrap script for javascript functions.</p>
<p>The bootstrap has a array intended to hold functions. Then there is a small &#8220;load&#8221; function which attach itself to &#8220;DOM readyness&#8221; and run trought the array of functions and fire the functions in it&#8217;s order in the array when the DOM is ready. For the &#8220;DOM readyness&#8221; detection I use the DOMContentLoaded which are supported in most new sane browsers and a small &#8220;hack&#8221; (<a href="http://javascript.nwbox.com/IEContentLoaded/" rel="nofollow">http://javascript.nwbox.com/IEContentLoaded/</a>) for detecting the same &#8220;DOM readyness&#8221; in IE. This way of detecting &#8220;DOM readyness&#8221; is pretty much the same way as JQuery and other JS libraries do.</p>
<p>I did post the bootstrap script with documentation, examples and the source a couple of weeks ago: <a href="http://www.trygve-lie.com/blog/entry/bootstraping_javascript" rel="nofollow">http://www.trygve-lie.com/blog/entry/bootstraping_javascript</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cancel bubble</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-720</link>
		<dc:creator>cancel bubble</dc:creator>
		<pubDate>Tue, 03 Mar 2009 18:01:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-720</guid>
		<description>There&#039;s an even shorter alternative with jQuery:

$(function() {
  // your code here
});</description>
		<content:encoded><![CDATA[<p>There&#8217;s an even shorter alternative with jQuery:</p>
<p>$(function() {<br />
  // your code here<br />
});</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Learning jQuery</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-693</link>
		<dc:creator>Learning jQuery</dc:creator>
		<pubDate>Fri, 26 Dec 2008 14:57:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-693</guid>
		<description>There is a shorthand alternative to $(document).ready(); Use this shortcut:

jQuery(function(){
// your code here
});</description>
		<content:encoded><![CDATA[<p>There is a shorthand alternative to $(document).ready(); Use this shortcut:</p>
<p>jQuery(function(){<br />
// your code here<br />
});</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maicon Peixinho</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-689</link>
		<dc:creator>Maicon Peixinho</dc:creator>
		<pubDate>Thu, 11 Dec 2008 11:48:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-689</guid>
		<description>There are other ways that do not require a specific framework for this, such as the function addLoadEvent () &quot;, which is added some methods in the page when all the elements are loaded.

Example:

function addLoadEvent(func) {
  if (!isWinLoaded){
	  var oldonload = window.onload;
	  if (typeof window.onload != &#039;function&#039;) {
	    window.onload = func;
	  } else {
	    window.onload = function() {
	      if (oldonload) {
	        oldonload();
	      }
	      func();
	    }
	  }
  }else{
	func();  	
  }
}
PS: &quot;isWinLoaded&quot; is a const set to false on onload of JS.


Excuse me shift the focus on the topic, but does not taste much of jquery, and therefore, shared a bit of a different note.

Thank you.</description>
		<content:encoded><![CDATA[<p>There are other ways that do not require a specific framework for this, such as the function addLoadEvent () &#8220;, which is added some methods in the page when all the elements are loaded.</p>
<p>Example:</p>
<p>function addLoadEvent(func) {<br />
  if (!isWinLoaded){<br />
	  var oldonload = window.onload;<br />
	  if (typeof window.onload != &#8216;function&#8217;) {<br />
	    window.onload = func;<br />
	  } else {<br />
	    window.onload = function() {<br />
	      if (oldonload) {<br />
	        oldonload();<br />
	      }<br />
	      func();<br />
	    }<br />
	  }<br />
  }else{<br />
	func();<br />
  }<br />
}<br />
PS: &#8220;isWinLoaded&#8221; is a const set to false on onload of JS.</p>
<p>Excuse me shift the focus on the topic, but does not taste much of jquery, and therefore, shared a bit of a different note.</p>
<p>Thank you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-688</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Mon, 08 Dec 2008 18:34:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-688</guid>
		<description>@Rick F
Thanks, I think that it&#039;s exactly what I was searching for. I&#039;ll try it and write a post about.</description>
		<content:encoded><![CDATA[<p>@Rick F<br />
Thanks, I think that it&#8217;s exactly what I was searching for. I&#8217;ll try it and write a post about.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick F</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-687</link>
		<dc:creator>Rick F</dc:creator>
		<pubDate>Mon, 08 Dec 2008 16:08:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-687</guid>
		<description>Have a look at the jQuery plugin &quot;LiveQuery&quot;.  I think it covers some of the cases you mention here.

http://plugins.jquery.com/project/livequery</description>
		<content:encoded><![CDATA[<p>Have a look at the jQuery plugin &#8220;LiveQuery&#8221;.  I think it covers some of the cases you mention here.</p>
<p><a href="http://plugins.jquery.com/project/livequery" rel="nofollow">http://plugins.jquery.com/project/livequery</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DevelX</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-686</link>
		<dc:creator>DevelX</dc:creator>
		<pubDate>Wed, 03 Dec 2008 16:13:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-686</guid>
		<description>Hm, well... I prefer this way:
if (document.addEventListener !== undefined) {
    document.addEventListener(&#039;load&#039;, init, false);
} else {
    document.attachEvent(&#039;onload&#039;, init);
}
This way you cannot make a collision with other scripts using document.load and such. But, well, you need to wait until all images etc are loaded.
But for the specific usage you need seems pawel&#039;s script good enough.</description>
		<content:encoded><![CDATA[<p>Hm, well&#8230; I prefer this way:<br />
if (document.addEventListener !== undefined) {<br />
    document.addEventListener(&#8216;load&#8217;, init, false);<br />
} else {<br />
    document.attachEvent(&#8216;onload&#8217;, init);<br />
}<br />
This way you cannot make a collision with other scripts using document.load and such. But, well, you need to wait until all images etc are loaded.<br />
But for the specific usage you need seems pawel&#8217;s script good enough.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-685</link>
		<dc:creator>Dan</dc:creator>
		<pubDate>Wed, 03 Dec 2008 13:19:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-685</guid>
		<description>@pawel Yeah... I think that&#039;s a good solution. Nicer and shorter than the &quot;each&quot; technique. Thanks a lot!</description>
		<content:encoded><![CDATA[<p>@pawel Yeah&#8230; I think that&#8217;s a good solution. Nicer and shorter than the &#8220;each&#8221; technique. Thanks a lot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pawel</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-684</link>
		<dc:creator>pawel</dc:creator>
		<pubDate>Wed, 03 Dec 2008 12:07:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-684</guid>
		<description>In external JavaScript file:

$(document).ready(function(){

if( $(&#039;ul#users&#039;)[0] ){
loadUsersWithAjax();
}

});

I think it does exactly what you want to do: no function calls in HTML document, calling loadUsersWithAjax() when the DOM is ready and only if there&#039;s &quot;ul#users&quot; in the DOM.</description>
		<content:encoded><![CDATA[<p>In external JavaScript file:</p>
<p>$(document).ready(function(){</p>
<p>if( $(&#8216;ul#users&#8217;)[0] ){<br />
loadUsersWithAjax();<br />
}</p>
<p>});</p>
<p>I think it does exactly what you want to do: no function calls in HTML document, calling loadUsersWithAjax() when the DOM is ready and only if there&#8217;s &#8220;ul#users&#8221; in the DOM.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
