<?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>Navarr&#039;s Tech Side &#187; desktop notifications</title>
	<atom:link href="http://tech.navarr.me/tag/desktop-notifications/feed" rel="self" type="application/rss+xml" />
	<link>http://tech.navarr.me</link>
	<description>The Technical Side of my Life</description>
	<lastBuildDate>Sun, 11 Jul 2010 00:52:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<cloud domain='tech.navarr.me' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Webkit JavaScript Notifications API</title>
		<link>http://tech.navarr.me/2010/01/webkit-javascript-notifications-api.html</link>
		<comments>http://tech.navarr.me/2010/01/webkit-javascript-notifications-api.html#comments</comments>
		<pubDate>Mon, 25 Jan 2010 20:29:51 +0000</pubDate>
		<dc:creator>Navarr</dc:creator>
				<category><![CDATA[Google Chrome]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[desktop notifications]]></category>
		<category><![CDATA[google chrome]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://tech.gtaero.net/2010/01/webkit-javascript-notifications-api.html</guid>
		<description><![CDATA[Something I learned about recently by following the updates being issued to Chrome, is that with today’s release they also pushed out the Webkit Notifications API to Chrome Stable (v4).&#160; Surprisingly, this is actually the first I’ve heard of it’s existence.&#160; I took a look and played around with it a bit, and it is [...]]]></description>
			<content:encoded><![CDATA[<p>Something I learned about recently by following the updates being issued to Chrome, is that with today’s release they also pushed out the Webkit Notifications API to Chrome Stable (v4).&#160; Surprisingly, this is actually the first I’ve heard of it’s existence.&#160; I took a look and played around with it a bit, and it is qué cool.</p>
<p>Visit <a href="http://sandbox.gtaero.net/chrome/notifications.php">my Sandbox</a> to see the code in action, or continue reading for some code excerpts.</p>
<p> <span id="more-365"></span>
<p>One interesting thing about this new API is that it not only requires a user to authorize it, but in order for an authorization click to appear, the user has to do something.&#160; You can’t make it appear as soon as the user visits the page, they have to click something or trigger an event.</p>
<p>For the sake of this example, lets say the user clicks a link that triggers the JavaScript function “notification();” and we want to show a notification onscreen.</p>
<pre><div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/About.html" target="_blank" title="Show plugin information"><img border="0" style="border: 0 none" src="http://tech.navarr.me/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> notification<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>window.<span style="color: #660066;">webkitNotifications</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// If we have the Notification API</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> nc <span style="color: #339933;">=</span> window.<span style="color: #660066;">webkitNotifications</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Set the API to nc for easy access</span>
		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>nc.<span style="color: #660066;">checkPermission</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// 1 = Not Allowed, 2 = Denied, 0 = Allowed</span>
		<span style="color: #009900;">&#123;</span>
			nc.<span style="color: #660066;">requestPermission</span><span style="color: #009900;">&#40;</span>myNotification<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Request Permission with a callback to myNotification();</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span> myNotification<span style="color: #009900;">&#40;</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;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> myNotification<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;">try</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> nc <span style="color: #339933;">=</span> window.<span style="color: #660066;">webkitNotifications</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> notif <span style="color: #339933;">=</span> nc.<span style="color: #660066;">createNotification</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;Notification Title&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;Notification Body&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Parameters: string URL_TO_IMAGE, string Title, string Body</span>
		notif.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Show Notification</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>Err<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>Err.<span style="color: #660066;">message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Will output a security error if we don't have permission.</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div></pre>
<p>As you can see from the code, its a fairly straightforward API for showing desktop notifications, and once the user has given the website permission, they can be triggered any time.  Up to five notifications can appear, and the rest will be kept in a queue until the others are dismissed, either by the user or by calling .cancel(); on the notification variable (notif in this case).</p>
]]></content:encoded>
			<wfw:commentRss>http://tech.navarr.me/2010/01/webkit-javascript-notifications-api.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
