<?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>Rowan &#187; javascript</title>
	<atom:link href="http://rowan.ijuru.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://rowan.ijuru.com</link>
	<description>Trying to make sense of it all</description>
	<lastBuildDate>Sun, 05 Oct 2008 15:46:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Saving the unsaved with a little Javascript</title>
		<link>http://rowan.ijuru.com/2008/09/07/saving-the-unsaved-with-a-little-javascript/</link>
		<comments>http://rowan.ijuru.com/2008/09/07/saving-the-unsaved-with-a-little-javascript/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 16:08:49 +0000</pubDate>
		<dc:creator>Rowan</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://rowan.ijuru.com/?p=238</guid>
		<description><![CDATA[Scenario: you make a nice HTML form for some purpose. A user comes along and spends some time filling it in&#8230; and then clicks a link on the page and loses everything they wrote. User never comes back to your site.
What you need is a little bit of Javascript to check for unsaved changes and [...]]]></description>
			<content:encoded><![CDATA[<p>Scenario: you make a nice HTML form for some purpose. A user comes along and spends some time filling it in&#8230; and then clicks a link on the page and loses everything they wrote. User never comes back to your site.</p>
<p>What you need is a little bit of Javascript to check for unsaved changes and warn the user before they leave the page if they are going to lose their work. <a href="http://ijuru.com/gutuma">Gutuma</a> uses something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> is_post_back <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
window.<span style="color: #660066;">onbeforeunload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>ev<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> html <span style="color: #339933;">=</span> document.<span style="color: #660066;">send_form</span>.<span style="color: #660066;">msg_html</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> subject <span style="color: #339933;">=</span> document.<span style="color: #660066;">send_form</span>.<span style="color: #660066;">msg_subject</span>.<span style="color: #660066;">value</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_post_back <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #009900;">&#40;</span>html <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">||</span> subject <span style="color: #339933;">!=</span> <span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;Your message will be lost if you leave this page.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> cancel_unsaved_warning<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  is_post_back <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The cancel function is called in the <code>onclick</code> events of any buttons on the page which do a POST back to the page, and thus won&#8217;t lose the user&#8217;s work. This is the best way I think to cancel the warning message as setting <code>window.onbeforeunload = null</code> doesn&#8217;t work in IE6, and returning <em>anything</em> from the <code>onbeforeunload</code> handler results in a warning message (even <code>null</code> or <code>false</code>), so you have to use some logic to avoid a return statement altogether. Weird but it works.</p>
<p><strong>UPDATE 11/09/08</strong>: I&#8217;ve just discovered that IE treats <code>javascript:</code> hrefs as navigations away from the page and fires the onbeforeunload event. So you can&#8217;t call a javscript function like</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;javascript:myfunc()&quot;&gt;Link&lt;/a&gt;</pre></div></div>

<p>without seeing the above warning message about leaving the page. But you can get around this by using the onclick attribute:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a onclick=&quot;javascript:myfunc()&quot; href=&quot;#&quot;&gt;Link&lt;/a&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://rowan.ijuru.com/2008/09/07/saving-the-unsaved-with-a-little-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX across domains</title>
		<link>http://rowan.ijuru.com/2008/09/06/ajax-across-domains/</link>
		<comments>http://rowan.ijuru.com/2008/09/06/ajax-across-domains/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 19:56:42 +0000</pubDate>
		<dc:creator>Rowan</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://rowan.ijuru.com/?p=227</guid>
		<description><![CDATA[Another problem I ran into in the course of my recent development of a PHP newsletter tool (Gutuma), was the restriction on AJAX requests to the same domain as the host page. I&#8217;ve developed some AJAX gadgets which can be placed on a user&#8217;s site and will send subscription requests to the newsletter tool&#8230; which [...]]]></description>
			<content:encoded><![CDATA[<p>Another problem I ran into in the course of my recent development of a PHP newsletter tool (<a href="http://ijuru.com/gutuma/">Gutuma</a>), was the restriction on AJAX requests to the same domain as the host page. I&#8217;ve developed some AJAX gadgets which can be placed on a user&#8217;s site and will send subscription requests to the newsletter tool&#8230; which might be hosted on a different domain.</p>
<p>If you&#8217;ve come across an &#8220;Access to restricted URI denied&#8221; error then you&#8217;re probably having the same problem. The solution is to use a proxy on the domain where the AJAX controls are hosted. This proxy receives the HTTP requests from the AJAX controls and can forward them on to the other domain.</p>
<p>For an example of how to do this, you can check out <a href="http://ijuru.com/gutuma/files/guproxy.zip">guproxy.php</a> which is my simple single file PHP script for forwarding AJAX requests (from the SACK AJAX library) to the AJAX interface of Gutuma. As a security precaution it limits forwarded requests based on the destination url, and the filters the POST variables to those used by Gutuma.  Other solutions I&#8217;ve seen don&#8217;t do this and thus leave your proxy script open to abuse.</p>
]]></content:encoded>
			<wfw:commentRss>http://rowan.ijuru.com/2008/09/06/ajax-across-domains/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Server-side Javascript merging</title>
		<link>http://rowan.ijuru.com/2008/09/05/server-side-javascript-merging/</link>
		<comments>http://rowan.ijuru.com/2008/09/05/server-side-javascript-merging/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 11:53:22 +0000</pubDate>
		<dc:creator>Rowan</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://rowan.ijuru.com/?p=214</guid>
		<description><![CDATA[Recently I&#8217;ve been working on PHP mailing list tool, and I wanted to make a simple Javascript API so that users can place dynamically generated gadgets onto their own pages. I wanted one JS file that could be included on a page, but as I was using a 3rd party AJAX Javascript library, this also [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been working on PHP mailing list tool, and I wanted to make a simple Javascript API so that users can place dynamically generated gadgets onto their own pages. I wanted one JS file that could be included on a page, but as I was using a 3rd party AJAX Javascript library, this also had to be included. Unfortunately Javascript has no concept of an <em>include </em>or <em>import </em>statement. So my solution was to use some PHP to merge them on the server:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: application/x-javascript'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
/**
 * This file is a server-side merge of first.js and second.js
 *
 * ------------------------------ first.js -------------------------------
 */
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'first.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
/**
 * ---------------------------- second.php ----------------------------
 */
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'second.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This simple approach could be used where you&#8217;ve got a lot of JS files and you want to speed up access times.</p>
]]></content:encoded>
			<wfw:commentRss>http://rowan.ijuru.com/2008/09/05/server-side-javascript-merging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
