<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Don Kitchen &#187; JavaScript</title>
	<atom:link href="http://www.donkitchen.com/category/programming/javascript-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.donkitchen.com</link>
	<description>programming, technology, fatherhood and life</description>
	<lastBuildDate>Wed, 31 Mar 2010 11:56:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Forcing a user to read (or scroll through) all text before accepting terms</title>
		<link>http://www.donkitchen.com/2009/12/10/forcing-a-user-to-read-or-scroll-through-all-text-before-accepting-terms/</link>
		<comments>http://www.donkitchen.com/2009/12/10/forcing-a-user-to-read-or-scroll-through-all-text-before-accepting-terms/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 23:39:58 +0000</pubDate>
		<dc:creator>Don</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.donkitchen.com/?p=329</guid>
		<description><![CDATA[If you&#8217;ve used a computer before you&#8217;ve undoubtedly scrolled through and agreed to some sort of agreement.  Most likely it was some sort of software license agreement that you didn&#8217;t read about some website you were signing up on or an application that you were installing. Maybe, if you&#8217;ve installed enough software or been on [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve used a computer before you&#8217;ve undoubtedly scrolled through and agreed to some sort of agreement.  Most likely it was some sort of <a href="http://en.wikipedia.org/wiki/Software_license_agreement" target="_blank">software license agreement</a> that you didn&#8217;t read about some website you were signing up on or an application that you were installing.</p>
<p>Maybe, if you&#8217;ve installed enough software or been on enough websites you&#8217;ve come across an instance where they actually forced you to scroll all the way down to the bottom of the text before you were able to click &#8220;I Agree&#8221; or whatever acknowledgment they wanted you to use.</p>
<p>Well I was recently faced with creating this exact situation in a web application and ended up using <a href="http://jquery.com/" target="_blank">jQuery </a>to accomplish this in my ASP.NET application.  For my particular situation I ended up putting my content inside a scrollable div.  This can easily be done by using a textbox if you wanted without much effort.</p>
<p>Basically, here&#8217;s what you&#8217;ll need.</p>
<ol>
<li>Reference jQuery (I&#8217;m not going to go into that, you can easily find that out <a href="http://jquery.com/" target="_blank">here</a>)</li>
<li>Put a DIV on your page containing your text that needs to scroll (obviously you&#8217;re putting more than a few sentences or you wouldn&#8217;t be in this boat)</li>
<li>Put a button on your page that, once enabled, will log the user&#8217;s acceptance and redirect them accordingly</li>
<li>Some simple JavaScript to tie the DIV&#8217;s scrolling event to your button</li>
</ol>
<p><strong>Here&#8217;s our DIV:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div style=&quot;width: 400px; height: 400px; overflow: auto; id=&quot;Terms&quot;&gt;
&lt;p&gt;Lots of text to read.&lt;/p&gt;
&lt;p&gt;Lots more text to read&lt;/p&gt;
&lt;/div&gt;</pre></div></div>

<p><strong>Here&#8217;s our button:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;asp:Button ID=&quot;ContinueButton&quot; runat=&quot;server&quot; Text=&quot;Continue&quot; /&gt;</pre></div></div>

<p><strong>Here&#8217;s our JavaScript:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">&lt;head runat=&quot;server&quot;&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.1.min.js&quot;&gt;&lt;/script&gt;
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
     $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
          <span style="color: #006600; font-style: italic;">// Initially disable the button</span>
          $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#ContinueButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;disabled&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;disabled&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #006600; font-style: italic;">// Map the function below to the scroll event of our Terms DIV</span>
          $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Terms&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">scroll</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#Terms&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">AtEnd</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #006600; font-style: italic;">// Enable the button once we reach the end of the DIV</span>
                    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#ContinueButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeAttr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;disabled&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #009900;">&#125;</span>
           <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">AtEnd</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">scrollTop</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">scrollHeight</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span> 
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&lt;/head&gt;</pre></div></div>

<p>And that&#8217;s it.  This code is light weight and works in IE, Firefox, Chrome and Safari.  Have any feedback or suggestions on how to make it better?  <a href="http://www.donkitchen.com/contact-me/">Let me know</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.donkitchen.com/2009/12/10/forcing-a-user-to-read-or-scroll-through-all-text-before-accepting-terms/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamically re-size an iFrame&#8217;s height across browsers</title>
		<link>http://www.donkitchen.com/2009/07/08/dynamically-re-size-an-iframes-height-across-browsers/</link>
		<comments>http://www.donkitchen.com/2009/07/08/dynamically-re-size-an-iframes-height-across-browsers/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 15:40:19 +0000</pubDate>
		<dc:creator>Don</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.donkitchen.com/?p=306</guid>
		<description><![CDATA[A while back I had a need to dynamically re-size an iFrame&#8217;s height and found a solution using a jQuery plug-in called autoHeight.  What I later found was that this solution provided poor results with Internet explorer when my iFrame&#8217;s contents were fairly large and frequently changing (i.e. via navigation inside the iFrame). It took [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I had a need to dynamically re-size an iFrame&#8217;s height and found a solution using a jQuery plug-in called <a href="http://lib.mobius.tw/jquery/myplugin/iframe_autoHeight/api.htm" target="_blank">autoHeight</a>.  What I later found was that this solution provided poor results with Internet explorer when my iFrame&#8217;s contents were fairly large and frequently changing (i.e. via navigation inside the iFrame).</p>
<p>It took quite a bit of tinkering but I was able to come up with a solution that works (and works well) in IE, Firefox, Safari and Chrome.  It still uses <a href="http://jquery.com/" target="_blank">jQuery</a> but doesn&#8217;t depend on a plug-in.  Here&#8217;s the code in case you&#8217;re looking for the same thing:</p>
<p>First, the iFrame&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;iframe src=&quot;Page1.htm&quot; id=&quot;MyFrame&quot; 
frameborder=&quot;0&quot; marginheight=&quot;0&quot; marginwidth=&quot;0&quot; 
width=&quot;800px&quot; height=&quot;100px&quot; scrolling=&quot;no&quot;&gt;&lt;/iframe&gt;</pre></div></div>

<p>Next, the JavaScript to resize it&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
     <span style="color: #003366; font-weight: bold;">function</span> sizeFrame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#MyFrame&quot;</span><span style="color: #339933;">,</span> top.<span style="color: #660066;">document</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #003366; font-weight: bold;">var</span> heightDiv <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#MyFrame&quot;</span><span style="color: #339933;">,</span> top.<span style="color: #660066;">document</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scrollHeight'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#MyFrame&quot;</span><span style="color: #339933;">,</span> top.<span style="color: #660066;">document</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> heightDiv <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     jQuery<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          sizeFrame<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#MyFrame&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span>sizeFrame<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>This line is needed to initially initialize the height so that it works in Safari and Chrome.  Without this line the window will never shrink to fit smaller content, it will just retain the last biggest height.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#MyFrame&quot;</span><span style="color: #339933;">,</span> top.<span style="color: #660066;">document</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> height<span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.donkitchen.com/2009/07/08/dynamically-re-size-an-iframes-height-across-browsers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
