<?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>Pressing the Red Button &#187; javascript</title>
	<atom:link href="http://www.pressthered.com/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pressthered.com</link>
	<description>Adventures in Software Development</description>
	<lastBuildDate>Sun, 08 Jan 2012 21:28:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Escaping Characters in JavaScript</title>
		<link>http://www.pressthered.com/escaping_characters_in_javascript/</link>
		<comments>http://www.pressthered.com/escaping_characters_in_javascript/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 06:46:50 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=368</guid>
		<description><![CDATA[Some characters can not be represented in a string in JavaScript, other characters might have a specific meaning in JavaScript. Here is a list of common escape sequences: \' &#09;Single Quote \n &#09;Newline \" &#09;Double Quote \t &#09;Tab \\ &#09;Backslash \b &#09;Backspace \f &#09;Form feed \r &#09;Carriage return To use, simply insert them into your [...]]]></description>
			<content:encoded><![CDATA[<p>Some characters can not be represented in a string in JavaScript, other characters might have a specific meaning in JavaScript. </p>
<pre>
<strong>Here is a list of common escape sequences:

\'   &#09;Single Quote
\n  &#09;Newline
\"  &#09;Double Quote
\t  &#09;Tab
\\  &#09;Backslash
\b  &#09;Backspace
\f  &#09;Form feed
\r  &#09;Carriage return
</strong>
</pre>
<p><strong>To use, simply insert them into your string:</strong></p>
<pre name="code" class="javascript">
var testStr = 'This a \'multi-line\' message.\nHere is the second line.';
alert(testStr);
</pre>
<p>These are the same escape sequences in the c, c++, and c# worlds.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/escaping_characters_in_javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing URLs in Javascript</title>
		<link>http://www.pressthered.com/parsing_urls_in_javascript/</link>
		<comments>http://www.pressthered.com/parsing_urls_in_javascript/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 06:18:36 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=379</guid>
		<description><![CDATA[Javascript does not have a built in method for parsing a url (to get the individual parts that make up a url). Here is a link to a great little function that does all you need, called parseURI. It uses regex to quickly break apart a url into source, protocol, authority, userInfo, user , password, [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript does not have a built in method for parsing a url (to get the individual parts that make up a url).  Here is a link to a great little function that does all you need, called <a href="http://blog.stevenlevithan.com/archives/parseuri">parseURI</a>.</p>
<p>It uses regex to quickly break apart a url into source, protocol, authority, userInfo, user , password, host, port, relative, path, directory, file, query, and anchor.</p>
<p>Here are few examples:</p>
<pre name="code" class="javascript">
var myUrl = "http://www.test.com/testdir/testfile.htm?q=test";

//get the host name of a url
alert( parseUri(myUrl).host );

//get the query string of a url
alert( parseUri(myUrl).query );

//get the path of the url
alert( parseUri(myUrl).path );
</pre>
<p>Here is a copy of the Steven Levithan&#8217;s code:</p>
<pre name="code" class="javascript">
/*
	parseUri 1.2.1
	(c) 2007 Steven Levithan &lt;stevenlevithan.com>
	MIT License
*/

function parseUri (str) {
	var	o   = parseUri.options,
		m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i   = 14;

	while (i--) uri[o.key[i]] = m[i] || "";

	uri[o.q.name] = {};
	uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
		if ($1) uri[o.q.name][$1] = $2;
	});

	return uri;
};

parseUri.options = {
	strictMode: false,
	key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
	q:   {
		name:   "queryKey",
		parser: /(?:^|&#038;)([^&#038;=]*)=?([^&#038;]*)/g
	},
	parser: {
		strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
		loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/parsing_urls_in_javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Full Page Refresh in Firefox</title>
		<link>http://www.pressthered.com/full_page_refresh_in_firefox/</link>
		<comments>http://www.pressthered.com/full_page_refresh_in_firefox/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 06:16:30 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=370</guid>
		<description><![CDATA[Hold down Control Key, Click Refresh Button or Control-F5 The keyboard shortcut is a bit of a hand stretch so I stick with the control key and mouse click. How does this help? Doing a full page refresh will go back to the web server to get the latest version of the page you are [...]]]></description>
			<content:encoded><![CDATA[<p>Hold down <strong>Control Key</strong>, Click<strong> Refresh Button</strong></p>
<p>or</p>
<p><strong>Control-F5</strong></p>
<p>The keyboard shortcut is a bit of a hand stretch so I stick with the control key and mouse click.</p>
<p><strong>How does this help?</strong><br />
Doing a full page refresh will go back to the web server to get the latest version of the page you are viewing. This helps with troubleshooting or when you are seeing results that are unexpected. To confirm you can force a refresh of the page.<br />
You might also find this helpful when coding on your local machine, sometimes the browser will not detect a javascript change you are working on. Getting in the habit of doing a full refresh will save your sanity.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/full_page_refresh_in_firefox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Navigating a JSON object in Javascript</title>
		<link>http://www.pressthered.com/navigating_a_json_object_in_javascript/</link>
		<comments>http://www.pressthered.com/navigating_a_json_object_in_javascript/#comments</comments>
		<pubDate>Sat, 27 Jun 2009 06:29:32 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=353</guid>
		<description><![CDATA[The Scenario: You are working with a web service that returns JSON. You&#8217;ve used your javascript library to convert the string into a JSON object. Now you need to access the data in the object using javascript. Here are some examples: JSON Property Types The properties of a JSON object are going to be of [...]]]></description>
			<content:encoded><![CDATA[<p><strong>The Scenario:</strong><br />
You are working with a web service that returns JSON. You&#8217;ve used your <a href="http://www.json.org/js.html">javascript library</a> to convert the string into a JSON object. Now you need to access the data in the object using javascript. Here are some examples:</p>
<p><strong>JSON Property Types</strong><br />
The properties of a JSON object are going to be of the following types: another Object or an Array of Objects. Objects are name &#8211; value pairs. The value that is returned can be a string, a number, another object, an array, true, false, or null.</p>
<p><strong>Accessing an Object type in JSON:</strong></p>
<pre name="code" class="javascript">
//A Simple Example:
// Your JSON object(yourData) has a name property,
//  you could get it this way:
var name = yourData.Name;
// alternatively you can use a string index:
var name = yourData["Name"];

//A Nested Example
// Your JSON object(yourData) has a Books object
//  with nested Book objects
var books = yourData.Books;
for (var x in books)
{
 var book = books[x];
 var title = book.title;
}
</pre>
<p><strong>Accessing an Array type in JSON:</strong></p>
<pre name="code" class="javascript">
//A Nested Example with an Array
// Your JSON object(yourData) has a
// Books array with nested Book objects
var books = yourData.Books;
for (var x = 0; x++; x< books.length)
{
 var book = books[x];
 var title = book.title;
}
</pre>
<p><strong>Getting Property Names</strong></p>
<pre name="code" class="javascript">
// When you want to know the name of the
//  properties of an object you can iterate
//  through the object using for - in loop
var books = yourData.Books;
for (var x in books)
{
 alert(x);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/navigating_a_json_object_in_javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>View, Browse, and Edit JSON Objects Visually</title>
		<link>http://www.pressthered.com/view_browse_and_edit_json_objects_visually/</link>
		<comments>http://www.pressthered.com/view_browse_and_edit_json_objects_visually/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 05:52:01 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JSON]]></category>

		<guid isPermaLink="false">http://www.pressthered.com/?p=272</guid>
		<description><![CDATA[Here are some helper applications that let you view, browse and edit JSON objects. When I am first working with a web service that returns JSON, I like a quick overview of what it includes. Having a navigable treeview helps find the properties that you need and get them quickly integrated into your code. Here [...]]]></description>
			<content:encoded><![CDATA[<p>Here are some helper applications that let you view, browse and edit JSON objects. When I am first working with a web service that returns JSON, I like a quick overview of what it includes. Having a navigable treeview helps find the properties that you need and get them quickly integrated into your code.</p>
<p><strong>Here they are:</strong></p>
<p><strong><a href="http://www.thomasfrank.se/json_editor.html">My JSON Editor</a> with <a href="http://www.thomasfrank.se/downloadableJS/JSONeditor_example.html">Demo</a></strong><br />
I like this one because it is simple and easy to use. You paste in your json string, click save and it gives you a quick tree view of your object.<br />
<div id="attachment_274" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.pressthered.com/wp-content/uploads/2009/06/json1-300x164.gif" alt="My JSON Editor" title="My JSON Editor" width="300" height="164" class="size-medium wp-image-274" /><p class="wp-caption-text">My JSON Editor</p></div></p>
<p><strong><a href="http://jsoneditor.appspot.com/">JSON Editor</a></strong><br />
This one works too.<br />
<div id="attachment_273" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.pressthered.com/wp-content/uploads/2009/06/json2-300x79.gif" alt="JSON Editor" title="JSON Editor" width="300" height="79" class="size-medium wp-image-273" /><p class="wp-caption-text">JSON Editor</p></div></p>
<p><strong><a href="http://www.softwareishard.com/blog/firebug/json-explorer-for-firebug/">Firebug JSON Explorer</a></strong><br />
I actually havn&#8217;t it tried this one, but it was definitely worth mentioning. I use Firebug but this feature is only available in the 1.4 beta. I wasn&#8217;t feeling brave enough to upgrade my Firebug version at the time of writing.</p>
<p><strong>What would be nice to see&#8230;</strong><br />
I would want to click on an element in the tree view and get the fully qualified javascript code to read the value. Save me some typing.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/view_browse_and_edit_json_objects_visually/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recording Javascript Errors</title>
		<link>http://www.pressthered.com/recording_javascript_errors/</link>
		<comments>http://www.pressthered.com/recording_javascript_errors/#comments</comments>
		<pubDate>Thu, 26 Oct 2006 00:11:03 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.pressingtheredbutton.com/recording_javascript_errors/</guid>
		<description><![CDATA[If you have started adding AJAX functionality into your applications, you learn real quick what your proficiency level in Javascript is. In my case, I was lacking and the inability to log or experience the javascript errors that clients were getting was frustrating. As a response, I set up a method to log the client [...]]]></description>
			<content:encoded><![CDATA[<p>If you have started adding AJAX functionality into your applications, you learn real quick what your proficiency level in Javascript is. In my case, I was lacking and the inability to log or experience the javascript errors that clients were getting was frustrating. As a response, I set up a method to log the client javascript errors directly to the server. Here is the story.</p>
<p>When I was developing an Ajax solution for an ecommerce application, compatibility was a major factor for acceptance by the client. Since I was relatively new to Ajax and my javascript skills were nothing special (at least when I started) I was concerned that the custom javascript code I was writing would have compatibility issues with all the browser choices out there (a valid concern indeed). </p>
<p>So here is the problem, I wanted to be notified when my ajax functions failed on the client and I wanted details. However when javascript fails on the client only the customer sees it.</p>
<p>Here was my solution. First I needed a way to catch when errors ocurred on the client. Two types of errors to be exact, javascript parsing errors (from null values sneaking into your variables for example) and errors that the <a href="http://www.ajaxpro.info/" target="_blank">ajax library</a> was returning (bad result from the server for example).</p>
<p>For the first type, javascript has it's own error handling functionality, so I do something  like:</p>
<div class="igBar"><span id="ljavascript-5"><a href="#" onclick="javascript:showPlainTxt('javascript-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-5">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">window.<span style="color: #000066;">onerror</span>=allErrors; <span style="color: #009900; font-style: italic;">//call the error handler below</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> allErrors<span style="color: #66cc66;">&#40;</span>desc,page,line,chr<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'An Error Has Occured!'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> msg =</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3366CC;">'JavaScript error occurred! <span style="color: #000099; font-weight: bold;">\n</span>'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; +<span style="color: #3366CC;">'The error was handled by '</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; +<span style="color: #3366CC;">'a customized error handler.<span style="color: #000099; font-weight: bold;">\n</span>'</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; +<span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>Error description: <span style="color: #000099; font-weight: bold;">\t</span>'</span>+desc</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; +<span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>Page address:&nbsp; &nbsp; &nbsp; <span style="color: #000099; font-weight: bold;">\t</span>'</span>+page</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; +<span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>Line number:&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000099; font-weight: bold;">\t</span>'</span>+line</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; ;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; sendErrorReport<span style="color: #66cc66;">&#40;</span>msg<span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">//used for logging, defined further below</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>For the second error type, most ajax libraries have an OnError event that is called when an invalid result comes back from the server during your ajax request . Mine did, so I simlply have to specify the function that gets called when the error occurs:</p>
<div class="igBar"><span id="ljavascript-6"><a href="#" onclick="javascript:showPlainTxt('javascript-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-6">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">AjaxPro.<span style="color: #000066;">onError</span> = ajaxError;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> ajaxError<span style="color: #66cc66;">&#40;</span>error<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> errorMsg = <span style="color: #3366CC;">'An Error Has Occured!'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>errorMsg<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; sendErrorReport<span style="color: #66cc66;">&#40;</span>error<span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">//used for logging, defined further below</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now I need a way to send those errors to my server so I get notified. I went with an old school Ajax approach but more simplified. The classic invisible IFRAME. However I don't need a result back, I just need a url request to go out and I need it to happen asyncronously (so the customer doesn't know or care).</p>
<p>Basically you just put an invisible iframe in the bottom of your html and write a simple function to send the result to the server. You can send anything you want to the server. I choose to send the error result that my ajax library returned. I html encoded (escaped) this error result and passed it to an aspx page. This aspx page then records the request headers so I can see what browser they are using and emails me this info and the error code that was passed as a parameter.</p>
<div class="igBar"><span id="lhtml-7"><a href="#" onclick="javascript:showPlainTxt('html-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">HTML:</span>
<div id="html-7">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">...</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><a href="http://december.com/html/4/element/iframe.html"><span style="color: #000000; font-weight: bold;">&lt;iframe</span></a> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"errorReporter"</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">frameborder</span>=<span style="color: #ff0000;">"0"</span><span style="color: #000000; font-weight: bold;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/iframe&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<div class="igBar"><span id="ljavascript-8"><a href="#" onclick="javascript:showPlainTxt('javascript-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JavaScript:</span>
<div id="javascript-8">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #003366; font-weight: bold;">function</span> sendErrorReport<span style="color: #66cc66;">&#40;</span>errorStr<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> oFrame = document.<span style="color: #006600;">getElementById</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">"errorReporter"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>oFrame<span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> d = <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #009900; font-style: italic;">//pass the date as a parameter so the request is never cached</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; errorStr = errorStr.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'&lt;'</span>,<span style="color: #3366CC;">'-'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; errorStr = errorStr.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'&gt;'</span>,<span style="color: #3366CC;">'-'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; oFrame.<span style="color: #006600;">src</span> = <span style="color: #3366CC;">"ErrorLogger.aspx?error="</span> + escape<span style="color: #66cc66;">&#40;</span>errorStr<span style="color: #66cc66;">&#41;</span> + <span style="color: #3366CC;">"&amp;time="</span> + d.<span style="color: #006600;">getTime</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">toString</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>What better way to QA your application then having your customer do it for you (I can hear the QA managers screaming now).  Anyway, this  allowed  me  to catch errors with incompatiable browsers. Some errors I couldn't do anything about, like ajax errors from the IE 5.2 browser for Macintosh (you have to draw the line somewhere when it comes to compatiablity).</p>
<p>However I found a few errors with my AJAX library with the latest AOL browser. This was unaccetable, I couldn't have the latest version of AOL not working with an ecommerce site.  Using the error information I recorded from the failed clients I was able to  fix a bug in my third party ajax library (yeah open source!).</p>
<p>If you're are curious, AOL's proxy servers send back custom status messages instead of the standard "200 OK" response. Granted I had to sign up for an AOL account to reproduce and fix the problem (hey it was a free ninety day account) but the fact that I had extensive error data collected made it an easy fix. Try collecting error information from upset customers (actually you have to collect it from your upset client who collects it from his upset customers which makes it worse).</p>
<p>So in conclusion, collecting the client errors remotely made me feel much more confident about my ajax application and ultimately made the application more robust.</p>
<p>Let me know if you have any questions or comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/recording_javascript_errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

