<?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/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=cleanest-way-of-executing-javascript-code-on-page-load</link>
	<description>helping you with javascript since 2007</description>
	<lastBuildDate>Tue, 31 Jan 2012 11:22:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-1412</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Mon, 17 Oct 2011 00:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-1412</guid>
		<description>I stumbled on this page via Google search and reading the comments it sounds like this is a smart group.  I&#039;m a complete newbie to Javascript, AJAX, and PHP and I&#039;m trying to figure out a way of passing on a data-value to a page when it loads and then use that data-value with a javascript that runs when the page loads.

I bought a WordPress template that the author stopped supporting and I need to find a solution to this problem.  If you go to http://www.stevenmichaeloconnor.com/series I am trying to get it so that if someone clicks on a Series Name such as &quot;Assorted&quot; it would go to the Portfolio page and then execute the javascript that the category menu is using and pass along the data-value=&quot;assorted&quot;.

This is the a href that the category menu is using on the Portfolio page to show only the &quot;Assorted&quot; category:
[code]&lt;a href=&quot;;&quot; rel=&quot;nofollow&quot;&gt;Assorted&lt;/a&gt;[/code]

I would be very grateful if anyone can help me out with this!

PB</description>
		<content:encoded><![CDATA[<p>I stumbled on this page via Google search and reading the comments it sounds like this is a smart group.  I&#8217;m a complete newbie to Javascript, AJAX, and PHP and I&#8217;m trying to figure out a way of passing on a data-value to a page when it loads and then use that data-value with a javascript that runs when the page loads.</p>
<p>I bought a WordPress template that the author stopped supporting and I need to find a solution to this problem.  If you go to http://www.stevenmichaeloconnor.com/series I am trying to get it so that if someone clicks on a Series Name such as &#8220;Assorted&#8221; it would go to the Portfolio page and then execute the javascript that the category menu is using and pass along the data-value=&#8221;assorted&#8221;.</p>
<p>This is the a href that the category menu is using on the Portfolio page to show only the &#8220;Assorted&#8221; category:<br />
[code]<a href=";" rel="nofollow">Assorted</a>[/code]</p>
<p>I would be very grateful if anyone can help me out with this!</p>
<p>PB</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leo</title>
		<link>http://www.javascriptkata.com/2008/12/01/cleanest-way-of-executing-javascript-code-on-page-load/comment-page-1/#comment-941</link>
		<dc:creator>Leo</dc:creator>
		<pubDate>Wed, 11 Aug 2010 01:02:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.javascriptkata.com/?p=69#comment-941</guid>
		<description>How about just moving the javascript to the bottom of the page?</description>
		<content:encoded><![CDATA[<p>How about just moving the javascript to the bottom of the page?</p>
]]></content:encoded>
	</item>
	<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>
</channel>
</rss>

