<?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>code-diesel &#187; html</title>
	<atom:link href="http://www.codediesel.com/category/html/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codediesel.com</link>
	<description>/* PHP &#38; MySQL Journal */</description>
	<lastBuildDate>Thu, 02 Feb 2012 13:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>The HTML5 keygen element</title>
		<link>http://www.codediesel.com/security/the-html5-keygen-element/</link>
		<comments>http://www.codediesel.com/security/the-html5-keygen-element/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 04:50:51 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2889</guid>
		<description><![CDATA[There is some confusion among users regarding the new HTML5 keygen element. The keygen element generates a public/private key pair and then creates a certificate request. Many users want to know the exact use of the element when SSL is available. This is my take on the subject. Correct me if I&#8217;m wrong. &#60;form action=&#34;process.cgi&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>There is some confusion among users regarding the new HTML5 <strong>keygen</strong> element. The <strong>keygen</strong> element generates a public/private key pair and then creates a certificate request. Many users want to know the exact use of the element when SSL is available. This is my take on the subject. Correct me if I&#8217;m wrong.</p>

<div class="wp_codebox"><table><tr id="p28892"><td class="code" id="p2889code2"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;process.cgi&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">enctype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;multipart/form-data&quot;</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;keygen <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;key&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span>submit <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Submit key...&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></td></tr></table></div>

<p><span id="more-2889"></span><br />
SSL is about &#8220;server identification&#8221; , &#8220;server AND client authentication&#8221; and &#8220;security&#8221;. During the normal SSL handshake the server presents its server-certificate so the browser can be sure that this is the correct server it is connecting to. But what should the server use to identify that it is the same user (browser) it is connecting to once the initial handshake has been done. For this purpose you need a client-certificate. The <strong>keygen</strong> element is used for creating a key for authentication of the user while SSL is concerned about privacy of communication and the authentication of the server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/the-html5-keygen-element/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Transform websites to mobile sites quickly</title>
		<link>http://www.codediesel.com/javascript/transform-websites-to-mobile-sites-quickly/</link>
		<comments>http://www.codediesel.com/javascript/transform-websites-to-mobile-sites-quickly/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 04:31:03 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mobile]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2887</guid>
		<description><![CDATA[Mobilize.js allows web developers create mobile sites out of existing websites with little effort. It supports the following features: Automatically detect mobile browsers. Easy to integrate – no server side changes needed. Open source – no expensive software or licenses needed. Familiar HTML5, Javascript and JQuery Mobile tools used. Supports iPhone, Android, Blackberry, Opera Mini [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://mobilizejs.com/" rel="nofollow" ><img src="http://www.codediesel.com/wp-content/uploads/2011/08/mobilejs.gif" alt="" title="mobilejs" width="75" height="121" class="alignleft size-full wp-image-2886" /></a><a href="http://mobilizejs.com/" rel="nofollow" target="_blank" >Mobilize.js</a> allows web developers create mobile sites out of existing websites with little effort. It supports the following features:</p>
<p>Automatically detect mobile browsers.<br />
Easy to integrate – no server side changes needed.<br />
Open source – no expensive software or licenses needed.<br />
Familiar HTML5, Javascript and JQuery Mobile tools used.<br />
Supports iPhone, Android, Blackberry, Opera Mini and other browsers and devices.</p>
<p>If you have a WordPress site, plugins are available for the same. To see exactly how mobile.js works, check <a href="http://cdn.mobilizejs.com/docs/trunk/manual/introduction.html#id3" rel="nofollow" target="_blank" >this section</a> of the documentation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/transform-websites-to-mobile-sites-quickly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Semantic markup for better search results</title>
		<link>http://www.codediesel.com/data/semantic-markup-for-better-search-results/</link>
		<comments>http://www.codediesel.com/data/semantic-markup-for-better-search-results/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 03:53:35 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[data]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[semantic web]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2867</guid>
		<description><![CDATA[Search-engines have reached a impasse with respect to understanding of HTML data. Although most sites, especially databases centric sites use structured data in the backend, once the data is rendered as HTML the data looses all its structure and makes it difficult for search engines to understand them correctly. Until now most search engines have [...]]]></description>
			<content:encoded><![CDATA[<p>Search-engines have reached a impasse with respect to understanding of HTML data. Although most sites, especially databases centric sites use structured data in the backend, once the data is rendered as HTML the data looses all its structure and makes it difficult for search engines to understand them correctly. Until now most search engines have relied on extracting keyword text from the web pages and ranking the pages accordingly, taking the context around the keyword into consideration. This obviously has its limitations and it can only take you so far.<br />
<span id="more-2867"></span><br />
Proper markup allows a web developer to add meaning or semantics to a page, but HTML has very little vocabulary which can help a person add semantics to a page. To help in this Endeavor, Microsoft, Yahoo and Google have released a shared vocabulary on <a href="http://schema.org" rel="nofollow" target="_blank" >schema.org</a>, which along with the <a href="http://dev.w3.org/html5/md/Overview.html" rel="nofollow" target="_blank" >microdata</a> format can help web developers add proper semantics to their data. This will help search engines to properly extract meaning from a web page which will enable them to provide richer search results, increased visibility of your web pages and possibly increased ranking. When three major search rivals collaborate on something you can be sure of the importance of it.</p>
<p>Below is a sample markup using the schema.org vocabulary and microdata.</p>
<p><strong>Original</strong>.</p>

<div class="wp_codebox"><table><tr id="p28675"><td class="code" id="p2867code5"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dell-30in-lcd.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
Dell UltraSharp 30&quot; LCD Monitor
&nbsp;
87 out of 100 based on 24 user ratings
&nbsp;
$1250 to $1495 from 8 sellers
&nbsp;
Sellers:
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;save-a-lot-monitors.com/dell-30.html&quot;</span>&gt;</span>
  Save A Lot Monitors - $1250<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jondoe-gadgets.com/dell-30.html&quot;</span>&gt;</span>
  Jon Doe's Gadgets - $1350<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></td></tr></table></div>

<p><strong>With semantic markup added.</strong></p>

<div class="wp_codebox"><table><tr id="p28676"><td class="code" id="p2867code6"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> itemscope itemtype<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://schema.org/Product&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;dell-30in-lcd.jpg&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;name&quot;</span>&gt;</span>Dell UltraSharp 30&quot; LCD Monitor<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
&nbsp;
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;aggregateRating&quot;</span> </span>
<span style="color: #009900;">    itemscope itemtype<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://schema.org/AggregateRating&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ratingValue&quot;</span>&gt;</span>87<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
    out of <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;bestRating&quot;</span>&gt;</span>100<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
    based on <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ratingCount&quot;</span>&gt;</span>24<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span> user ratings
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;offers&quot;</span> </span>
<span style="color: #009900;">    itemscope itemtype<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://schema.org/AggregateOffer&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lowPrice&quot;</span>&gt;</span>$1250<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
    to <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;highPrice&quot;</span>&gt;</span>$1495<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
    from <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;offerCount&quot;</span>&gt;</span>8<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span> sellers
&nbsp;
  Sellers:
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;offers&quot;</span> itemscope itemtype<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://schema.org/Offer&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;save-a-lot-monitors.com/dell-30.html&quot;</span>&gt;</span>
     Save A Lot Monitors - $1250<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;offers&quot;</span> itemscope itemtype<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://schema.org/Offer&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> itemprop<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;url&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;jondoe-gadgets.com/dell-30.html&quot;</span>&gt;</span>
     Jon Doe's Gadgets - $1350<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  ...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Although this may seem a lot of extra work and time, the efforts will pay handsomely over a period as more people adopt semantic markup and companies come up with better  tools and APIs to work with the new data.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/data/semantic-markup-for-better-search-results/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharing data across windows using localStorage</title>
		<link>http://www.codediesel.com/javascript/sharing-messages-and-data-across-windows-using-localstorage/</link>
		<comments>http://www.codediesel.com/javascript/sharing-messages-and-data-across-windows-using-localstorage/#comments</comments>
		<pubDate>Mon, 13 Jun 2011 07:28:39 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[browser]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2832</guid>
		<description><![CDATA[One of a common requirement in some web applications is that of sending messages and data across windows (of the same origin). Doing this is not easy and requires the help of cookies and a bit of JavaScript. Now with HTML5 and its localStorage feature we can accomplish this quite easily. Storage Events Whenever a [...]]]></description>
			<content:encoded><![CDATA[<p>One of a common requirement in some web applications is that of sending messages and data across windows (of the same origin). Doing this is not easy and requires the help of cookies and a bit of JavaScript. Now with HTML5 and its localStorage feature we can accomplish this quite easily.<br />
<span id="more-2832"></span></p>
<h4>Storage Events</h4>
<p>Whenever a <em>localStorage</em> object is changed using the <em>setItem()</em>, <em>removeItem()</em>, or <em>clear()</em> functions, the <em>storage</em> event is fired (across multiple windows of the same origin) by the browser, we can trap this event and use it to share messages or data across windows. Check the following demo to see how this works in a simple case.</p>
<p><a href="http://www.codediesel.com/demos/localstorage/index.php"class="view_demo"  target="_blank"></a></p>
<p>The above example works by using the storage event of the Window object. So whenever the localStorage object is modified, the <em>storage</em> event is fired and we use it to update the window content.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/06/localstorage.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/06/localstorage.gif" alt="" title="localstorage" width="437" height="361" class="aligncenter size-full wp-image-2834" /></a></p>

<div class="wp_codebox"><table><tr id="p283210"><td class="code" id="p2832code10"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;storage&quot;</span><span style="color: #339933;">,</span> displayStorageEvent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Below is the skeleton code for the demo example.</p>

<div class="wp_codebox"><table><tr id="p283211"><td class="code" id="p2832code11"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Input element</span>
<span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'data'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// Element to display the updated data</span>
<span style="color: #003366; font-weight: bold;">var</span> output <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'event-data'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> displayStorageEvent<span style="color: #009900;">&#40;</span>e<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>e.<span style="color: #660066;">key</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'storage-event'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        output.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> e.<span style="color: #660066;">newValue</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> updateStorageEvent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'storage-event'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
window.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;storage&quot;</span><span style="color: #339933;">,</span> displayStorageEvent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
data.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;keyup&quot;</span><span style="color: #339933;">,</span> updateStorageEvent<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Sharing messages</h4>
<p>Although in the above example we are sharing data across windows, we can use the same mechanism to share messages. In the above example we are using the &#8216;storage-event&#8217; key to store the data we type in the input box. Instead we can pass a simple message. The syntax remains the same, only the semantics changes.</p>

<div class="wp_codebox"><table><tr id="p283212"><td class="code" id="p2832code12"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Store the 'checkPassword' message in the 'app.message.auth' key */</span>
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'app.message.auth'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;checkPassword&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* Store the 'dataSave' message in the 'app.message.status' key */</span>
localStorage.<span style="color: #660066;">setItem</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'app.message.status'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;dataSave&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Security concerns</h4>
<p>As the communication can only happen between windows with the same origin, there is little risk of data leak between sites. Still you should refrain from storing sensitive information in the storage.</p>
<h4>Possible applications</h4>
<p>Now that we have seen a simple proof of concept of &#8216;cross window messaging and data sharing&#8217;, what are the potential use cases of the same. An idea without a concrete and useful application is useless. Although many people will have good ideas for the above concept, I presently lack one. So if you can think of some nice use cases for this, please voice your ideas in the comments section.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/sharing-messages-and-data-across-windows-using-localstorage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding HTML5 Geolocation to your web applications</title>
		<link>http://www.codediesel.com/javascript/adding-html5-geolocation-to-your-applications/</link>
		<comments>http://www.codediesel.com/javascript/adding-html5-geolocation-to-your-applications/#comments</comments>
		<pubDate>Fri, 13 May 2011 06:09:21 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2815</guid>
		<description><![CDATA[One of the interesting and useful addition to the HTML5 specification is the Geolocation API. The Geolocation API allows users to share their location with web applications so that they can enjoy the benefits of various location-aware services. Geolocation enables you as a developer or website owner to figure out where a particular user is [...]]]></description>
			<content:encoded><![CDATA[<p>One of the interesting and useful addition to the HTML5 specification is the Geolocation API. The Geolocation API allows users to share their location with web applications so that they can enjoy the benefits of various location-aware services.</p>
<p>Geolocation enables you as a developer or website owner to figure out where a particular user is located on the planet. This can be helpful in various web applications; for example in social networking, where you can find out where your various friends are currently located or in advertising where you can  display targeted ads based on the users location.<br />
<span id="more-2815"></span></p>
<h4>Getting your users location</h4>
<p>In the past, IP based geolocation was the only way to get a users possible location. Services and databases such as  <a href="http://www.maxmind.com/app/geoip_country" rel="nofollow" target="_blank" >MaxMind</a> or <a href="http://www.ip2location.com/" rel="nofollow" target="_blank" >ip2location</a> where used to locate the position of the user, based on the users IP address.</p>
<p>Now that Geolocation is available as a built-in API service in HTML5, it makes easier for developers to quickly integrate location based services into their applications.</p>
<p><a href="http://www.codediesel.com/demos/geolocation"class="view_demo" target="_blank" ></a></p>
<h4>Detecting Geolocation support</h4>
<p>Before you write any Geolocation code you need to check if it is supported on your browser. The simplest way to detect if Geolocation is supported is to use the global &#8216;navigator&#8217; object.</p>

<div class="wp_codebox"><table><tr id="p281521"><td class="code" id="p2815code21"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">// Geolocation supported. Do something here.</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>Reading users location</h4>
<p>Once we have checked that Geolocation is supported we can use the following to get the users location data.</p>

<div class="wp_codebox"><table><tr id="p281522"><td class="code" id="p2815code22"><pre class="javascript" style="font-family:monospace;">navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span>success_handler<span style="color: #339933;">,</span> error_handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This will execute the callback function &#8216;success_handler&#8217; if the request is successful or the &#8216;error_handler&#8217; callback if some error occurs. The location data is available as a &#8216;position&#8217; object in the &#8216;success_handler&#8217;.</p>

<div class="wp_codebox"><table><tr id="p281523"><td class="code" id="p2815code23"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> success_handler<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        latitude <span style="color: #339933;">=</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span><span style="color: #339933;">;</span>
        longitude <span style="color: #339933;">=</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span><span style="color: #339933;">;</span>
        accuracy <span style="color: #339933;">=</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">accuracy</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Below is a list of all properties available:</p>
<table class="posts_table">
<colgroup>
<col width="36%" />
<col width="38%" />
<col width="26%" />
</colgroup>
<thead valign="bottom">
<tr>
<th class="head"><strong>Property</strong></th>
<th class="head"><strong>Data Type</strong></th>
<th class="head"><strong>Unit</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr>
<td>coords.latitude</td>
<td>double</td>
<td>decimal degrees</td>
</tr>
<tr>
<td>coords.longitude</td>
<td>double</td>
<td>decimal degrees</td>
</tr>
<tr>
<td>coords.altitude</td>
<td>meters</td>
<td>decimal degrees</td>
</tr>
<tr>
<td>coords.accuracy</td>
<td>double</td>
<td>meters</td>
</tr>
<tr>
<td>coords.altitudeAccuracy</td>
<td>double or null</td>
<td>meters</td>
</tr>
<tr>
<td>coords.heading</td>
<td>double or null</td>
<td>degrees</td>
</tr>
<tr>
<td>coords.speed</td>
<td>double or null</td>
<td>meters/second</td>
</tr>
<tr>
<td>timestamp</td>
<td>DOMTimeStamp</td>
<td>Date() object</td>
</tr>
</tbody>
</table>
<h4>User privacy</h4>
<p>When you opened the demo web page given above you may have received a notification bar like the following; this bar requests your permission to share your location with the browser.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/05/geo-location.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/05/geo-location.gif" alt="" title="geo-location" width="603" height="25" class="aligncenter size-full wp-image-2817" /></a></p>
<p>The HTML5 Geolocation specification mandates that before any location data can be retrieved the browser first request permission from the user to share its location. Only when the user allows does the browser retrieves the users location. </p>
<blockquote><p>
<strong>Note:</strong> If opted to &#8216;always share&#8217; or &#8216;always deny&#8217; in Firefox and later change your mind, you can easily revert permissions by going back to the website and selecting &#8216;Tools&#8217; menu->&#8217;Page Info&#8217; in Firefox. Then change the setting for &#8216;Share Location&#8217; on the Permissions tab.
</p></blockquote>
<h4>How does Geolocation work</h4>
<p>Once you give permission to the browser to share your location, the browser gathers information about nearby access points and also your computer’s IP address which the browser then sends to the default geolocation service provider &#8211; Google Location Services in case of Firefox, to get an estimate of your location. This location estimate is then sent to the requesting website.</p>
<h4>Location accuracy</h4>
<p>You may have noticed above that the &#8216;position&#8217; object returns a <strong>accuracy</strong> variable. <strong>accuracy</strong> represents a value in meters which specifies how close the latitude and longitude values are to the actual location. You can increase the location accuracy by passing a option to the <strong>getCurrentPosition</strong> function. Bear in mind that this is only a hint that you give to the browser; whether it returns a high accuracy result depends on the location service your browser uses.</p>

<div class="wp_codebox"><table><tr id="p281524"><td class="code" id="p2815code24"><pre class="javascript" style="font-family:monospace;">navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span>
                                    success_handler<span style="color: #339933;">,</span> 
                                    error_handler<span style="color: #339933;">,</span> 
                                    <span style="color: #009900;">&#123;</span>enableHighAccuracy<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Saving location to Cookies</h4>
<p>Once we get the location data from the user it is better to store it for the entire session so we can use it on other pages. Storing it in cookies is one quick option. For this example I&#8217;ve used the jQuery <a href="http://plugins.jquery.com/project/Cookie" rel="nofollow" target="_blank" >cookie plugin</a>, which provides a simple and clean way to save and retrieve cookies.</p>
<p>We can store the cookies in the &#8216;success_handler&#8217; and then later check the same before issuing another location request.</p>

<div class="wp_codebox"><table><tr id="p281525"><td class="code" id="p2815code25"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> success_handler<span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #009966; font-style: italic;">/* Get the location data */</span>
        latitude <span style="color: #339933;">=</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">latitude</span><span style="color: #339933;">;</span>
        longitude <span style="color: #339933;">=</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">longitude</span><span style="color: #339933;">;</span>
        accuracy <span style="color: #339933;">=</span> position.<span style="color: #660066;">coords</span>.<span style="color: #660066;">accuracy</span><span style="color: #339933;">;</span>
&nbsp;
        $.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;posLat&quot;</span><span style="color: #339933;">,</span> latitude<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;posLon&quot;</span><span style="color: #339933;">,</span> longitude<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;posAccuracy&quot;</span><span style="color: #339933;">,</span> accuracy<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Now that we have nicely saved the data, all the other site pages can now access the location data by reading them from the cookies.</p>

<div class="wp_codebox"><table><tr id="p281526"><td class="code" id="p2815code26"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Check if location data is available in the cookies */</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;posLat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    latitude  <span style="color: #339933;">=</span> $.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;posLat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    longitude <span style="color: #339933;">=</span> $.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;posLon&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    accuracy  <span style="color: #339933;">=</span> $.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;posAccuracy&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">// do something here</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>Continuous Position Updates</h4>
<p>In the above example the location was read once and stored for future use. But what if your application is on a mobile device and you are on the move. The Geolocation API provides another function <strong>navigator.geolocation.watchPosition</strong> that automatically retrieves the users current location if it ever changes. The function is similar to &#8216;getCurrentPosition&#8217;, the only difference is that it regularly polls the location and returns the new location data.</p>

<div class="wp_codebox"><table><tr id="p281527"><td class="code" id="p2815code27"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> watch_id <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">watchPosition</span><span style="color: #009900;">&#40;</span>
                                        success_handler<span style="color: #339933;">,</span> 
                                        error_handler
                                        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The function return a unique numeric id which you can later use to stop the polling.</p>

<div class="wp_codebox"><table><tr id="p281528"><td class="code" id="p2815code28"><pre class="javascript" style="font-family:monospace;">navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">clearWatch</span><span style="color: #009900;">&#40;</span>watch_id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/adding-html5-geolocation-to-your-applications/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Internationalisation and Localisation of Web Applications</title>
		<link>http://www.codediesel.com/html/internationalisation-and-localisation-of-web-applications/</link>
		<comments>http://www.codediesel.com/html/internationalisation-and-localisation-of-web-applications/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 11:06:34 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[Internationalisation]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[Localisation]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2812</guid>
		<description><![CDATA[If you’re designing a web application, you may think that developing it in English will be quite enough. Remember, though, that only 22% of internet users speak English as their native language, and 85% of ecommerce consumers won’t buy a product if they can’t read about it in their native language, which leaves only one [...]]]></description>
			<content:encoded><![CDATA[<p>If you’re designing a web application, you may think that developing it in English will be quite enough. Remember, though, that only 22% of internet users speak English as their native language, and 85% of ecommerce consumers won’t buy a product if they can’t read about it in their native language, which leaves only one question to be asked: are you prepared to miss on those millions of potential customers?</p>
<p>Software developers worldwide know that a web application will only work the way it’s supposed to for its target market. Even if two countries speak the same language, there are plenty of other things to consider when it comes to localising an app. Take, for example, the UK and the United States. The date format in the UK is day/month/year, while the US uses month/day/year, which could be cause for problems if an app is not localised for its specific market.<br />
<span id="more-2812"></span><br />
But before we move forward, you’re due an explanation of what internationalisation and localisation are. Internationalisation is the technical process of preparing a web application for use in a range of different countries without further changes to the platform. Localisation means adapting a web application for a specific market, translating the text and taking into consideration every component of the app.  </p>
<p>This is a two-step process, because internationalisation is a precursor of localisation. Developing an application to reach a large number of countries from the start will simplify the process of localisation later on. Having an internationalised web app from the get go will ensure that once you figure out the market, you’ll only need to translate the text and change the necessary formats, rather than having to start from scratch. </p>
<h4>The internationalisation process </h4>
<p>Not every web application can be internationalised in the same way. From differences in platform to the very basics of the application, there are key differences programmers must identify before starting work.  Nevertheless, there are some basic internationalisation principles that can be applied universally.</p>
<p>If your application is to be developed using English as its base language, the best thing to do is use clear and simple language. Remember that once the localisation process begins, the text will have to be translated, and nothing makes the translation process more difficult than dealing with abbreviations, jargon or slang in the text. </p>
<p>Another thing you should keep in mind is that not all languages require the same amount of space. For example, a sentence in German will, in general, be around 30% longer than the equivalent sentence in English. If your app hasn’t been designed with enough space for extra characters then you may end up with serious formatting issues. It’s always a good idea to design apps with room for text to grow or shrink.</p>
<p>If you do have to set a fixed space for the text, remember to inform your translators of the available space before they start work, so they can work with that character limit in mind and won’t have to skip any text to make the content fit. </p>
<h4>The localisation process</h4>
<p>The most important part of the localisation process is translation. The best course of action is to hire a native translator. As you might already know, translation is more than just changing words between languages &#8211; it requires a cultural background in the target language to understand nuance and subtlety, which something machine translation programs can’t do. </p>
<p>Before you hire translators and start localising your app for a range of languages, though, it pays to take a closer look at which countries actually have a gap in the market that can be filled by your app – for instance, if you’ve developed an application that’s specifically designed to link with Facebook then there’s not really any point localising it for China, where Facebook has no market presence.</p>
<p>Once you’ve identified the best foreign markets for your app, the localization process involves researching the specific charts and tables of the country, such as date formats, measurements of length, temperature, weight, currency, etc, to ensure your app feels like it’s been designed specifically for that audience.</p>
<h4>Cultural differences</h4>
<p>There’s more to developing a localised software app than just translating the text and changing the formats and measurements, though. Visual symbols, colour, images and icons are also an important part. Colours can be crucially important, as they can have widely differing meanings in different cultures, for instance, white is often interpreted as being ‘peaceful’ in Western societies, but it’s a colour associated with death and funerals in China. A little research can go a long way to developing the perfect app for your market of choice. </p>
<p>Icons and images are another integral part of your web application and should be picked after thorough consideration. A ‘thumbs-up’ icon is widely accepted in western societies (see Facebook’s ‘like’ button), but it’s also seen as very offensive in some parts of the world, such as parts of Africa and the Middle East, where it has a similar meaning to the middle finger in western cultures. The same can be said of the ‘table’ icon, which signifies a spreadsheet to English-speakers, but not to anyone else.</p>
<p>Developing a multilingual internationalised and localised web application isn’t the easiest thing in the world, but creating a detailed project plan and conducting thorough research of your target markets will make the process infinitely easier. </p>
<blockquote><p>
<a href="http://www.codediesel.com/wp-content/uploads/2011/04/Christian_lingo24.jpg"><img src="http://www.codediesel.com/wp-content/uploads/2011/04/Christian_lingo24.jpg" alt="" title="Christian_lingo24" width="87" height="91" class="alignleft size-full wp-image-2814" /></a>This guest post was written by Christian Arno. Christian  is the founder of <a href="http://www.lingo24.com/" rel="nofollow" target="_blank" >professional translation agency</a> Lingo24. Launched in 2001, Lingo24 now has over 150 employees spanning three continents and clients in over sixty countries. Follow Christian (<a href="http://twitter.com/l24ca" rel="nofollow" target="_blank" >@l24ca</a>) and Lingo24 (<a href="http://twitter.com/lingo24" rel="nofollow" target="_blank" >@Lingo24</a>) on Twitter.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/html/internationalisation-and-localisation-of-web-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Adobe Flash FLA files into HTML</title>
		<link>http://www.codediesel.com/tools/convert-adobe-flash-fla-files-into-html/</link>
		<comments>http://www.codediesel.com/tools/convert-adobe-flash-fla-files-into-html/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 10:27:44 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[Wallaby]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2802</guid>
		<description><![CDATA[With Adobe Flash not being natively supported by Apple iOS, there have been some attempts from programmers to convert Flash files to HTML, such as SmokeScreen and Gordon; which will help developers easily port existing Flash content to iOS devices (iPad, iPhone). Not to be left behind on its own turf, Adobe has come up [...]]]></description>
			<content:encoded><![CDATA[<p>With Adobe Flash not being natively supported by Apple iOS, there have been some attempts from programmers to convert Flash files to HTML, such as <a href="http://smokescreen.us/" rel="nofollow" target="_blank" >SmokeScreen</a> and <a href="https://github.com/tobeytailor/gordon/" rel="nofollow" target="_blank" >Gordon</a>; which will help developers easily port existing Flash content to iOS devices (iPad, iPhone). Not to be left behind on its own turf, Adobe has come up with its own conversion tool, &#8220;Wallaby&#8221;.</p>
<p><a href="http://www.codediesel.com/wp-content/uploads/2011/03/flash_converter.gif"><img src="http://www.codediesel.com/wp-content/uploads/2011/03/flash_converter.gif" alt="" title="flash_converter" width="330" height="214" class="aligncenter size-full wp-image-2804" /></a></p>
<p>&#8220;Wallaby&#8221; is the codename for an experimental technology that converts Flash content (FLA files) into HTML 5. This allows you to reuse existing Flash content on devices that do not support Flash. Once converted to HTML, you can easily edit them using Adobe Dreamweaver or any other editing tools.<br />
<span id="more-2802"></span><br />
Wallaby comes as a desktop <a href="http://www.adobe.com/products/air/" rel="nofollow" target="_blank" >Adobe Air</a> application so you will need the <a href="http://get.adobe.com/air/" rel="nofollow" target="_blank" >AIR runtime</a> installed on your system to run the application.</p>
<p>Wallaby uses SVG instead of Canvas to recreate the output because SVG is rendered natively by the browser while Canvas is drawn with JavaScript, which tends to slow down the rendering. According to experiments carried out by Adobe, Canvas was a lot slower than SVG on portable devices. Another point cited by Adobe for favoring SVG is that of readability. Using Canvas lowers the readability of the HTML since the output becomes a program instead of markup as in SVG.</p>
<p>Note that as of now not all Flash Professional features are supported in the HTML5 format, so Flash files above average complexity will not be rendered properly. I tried converting a few FLA files but met with a few conversion errors, mainly that of incompatible file format. As Adobe is desperate to make its presence felt in the portable devices market, expect a more complete working product by 2011 end.</p>
<p>You can download Wallaby from <a href="http://labs.adobe.com/downloads/wallaby.html" rel="nofollow" target="_blank" >Adobe Labs</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/tools/convert-adobe-flash-fla-files-into-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML 5 logo announced</title>
		<link>http://www.codediesel.com/html/html-5-logo-announced/</link>
		<comments>http://www.codediesel.com/html/html-5-logo-announced/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 05:53:53 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2785</guid>
		<description><![CDATA[Now that people have slowly started implementing HTML 5 features in their sites they would like the world to know the same. W3C have released a set of logos you can stick on your site and announce the world of your HTML 5 accomplishments. Besides the primary logo it also include logos for other main [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codediesel.com/wp-content/uploads/2011/01/HTML5_Logo_128.png"><img src="http://www.codediesel.com/wp-content/uploads/2011/01/HTML5_Logo_128.png" alt="html 5 logo" title="HTML5_Logo_128" width="128" height="128" class="alignleft size-full wp-image-2786" /></a> Now that people have slowly started implementing HTML 5 features in their sites they would like the world to know the same. W3C have released a set of <a href="http://www.w3.org/html/logo/" rel="nofollow" target="_blank" >logos</a> you can stick on your site and announce the world of your HTML 5 accomplishments. Besides the primary logo it also include logos for other main features of HTML 5 &#8211; CSS, semantics, offline storage etc.<br />
<span id="more-2785"></span><br />
They also have a online badge builder that will quickly let you create one for your site. And if you are one of those that like to strut their stuff, W3C also provides t-shirts and other cool things to impress mortals around you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/html/html-5-logo-announced/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introducing HTML5 Web Workers</title>
		<link>http://www.codediesel.com/javascript/introducing-html5-web-workers/</link>
		<comments>http://www.codediesel.com/javascript/introducing-html5-web-workers/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 05:44:22 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[html5]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2780</guid>
		<description><![CDATA[One of the interesting and useful additions to the HTML5 standards is the support for Web Workers. Web Workers will help you design more responsive web applications then otherwise possible in the past. What are Web Workers Web Workers are basically a API specification that lets you create background JavaScript threads to process CPU intensive [...]]]></description>
			<content:encoded><![CDATA[<p>One of the interesting and useful additions to the HTML5 standards is the support for Web Workers. Web Workers will help you design more responsive web applications then otherwise possible in the past.</p>
<h4>What are Web Workers</h4>
<p>Web Workers are basically a API specification that lets you create background JavaScript threads to process CPU intensive tasks. Normally in browsers a single thread is created to handle all the JavaScript code. So whatever JavaScript code is run in the browser is executed in that single thread; whether you are doing some calculation or updating page elements. The downside of this is that some CPU intensive piece of JavaScript can render the page unresponsive or slow it to a crawl. </p>
<p>Web Workers alleviate this problem by letting you create multiple JavaScript threads that will run independent of each other, this will prevent one CPU intensive piece of JavaScript from interfering with the UI code.<br />
<span id="more-2780"></span></p>
<h4>Checking Web Worker support</h4>
<p>Before you create any Web Worker related code you will need to find if your browser supports HTML5 Web Workers. Failure to do this will send your Web Workers to slog in Never Never Land. The following code will allow you to check if your browser supports Web Workers.</p>

<div class="wp_codebox"><table><tr id="p278037"><td class="code" id="p2780code37"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Check if Web Workers are supported */</span>
<span style="color: #003366; font-weight: bold;">function</span> getWebWorkerSupport<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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>Worker<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h4>Creating a simple Worker</h4>
<p>Once we have checked that Workers are supported in the browser we are ready to put them to task. In this example we will create a simple Web Worker that will &#8216;Add&#8217; or &#8216;Multiply&#8217; two numbers. The example is deliberately kept simple to keep the discussion focused on Worker details; in reality you would not use Workers for such simple things, but for more elaborate and CPU intensive tasks. Below is a small piece of JavaScript code that does the actual arithmetic calculation. This our Worker. It is stored in the &#8216;arithmetic.js&#8217; file.</p>

<div class="wp_codebox"><table><tr id="p278038"><td class="code" id="p2780code38"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* arithmetic.js */</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> addNumbers<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> x <span style="color: #339933;">+</span> y<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> mulNumbers<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span>y<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> x<span style="color: #339933;">*</span>y<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/* 
   Add a event listener to the worker, this will
   be called when the worker receives a message
   from the main page.
*/</span>
<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">onmessage</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> event.<span style="color: #660066;">data</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">switch</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">op</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'mult'</span><span style="color: #339933;">:</span>
        postMessage<span style="color: #009900;">&#40;</span>mulNumbers<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> data.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'add'</span><span style="color: #339933;">:</span>
        postMessage<span style="color: #009900;">&#40;</span>addNumbers<span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">x</span><span style="color: #339933;">,</span> data.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
        <span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
        postMessage<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Wrong operation specified&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: #339933;">;</span></pre></td></tr></table></div>

<p>Now that we have or Worker file ready we need to call it from our main file.<br />
The following line will create a new Worker thread and run the code stored in &#8216;arithmetic.js&#8217;.</p>

<div class="wp_codebox"><table><tr id="p278039"><td class="code" id="p2780code39"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Create a new worker */</span>
    arithmeticWorker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Worker<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;arithmetic.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Once we have created Workers we need to send and receive messages from them. For that we need to add a event handler to the main calling code.</p>

<div class="wp_codebox"><table><tr id="p278040"><td class="code" id="p2780code40"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* 
   Add a event listener to the worker, this will
   be called whenever the worker posts any message.
*/</span>
arithmeticWorker.<span style="color: #660066;">onmessage</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;output&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> event.<span style="color: #660066;">data</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Now whenever a Worker posts a message the &#8216;onmessage&#8217; event is fired and the code within it is executed. The data passed by the Worker is stored in the event.data container. We have seen how to receive a message from the Worker but how to we post one. Posting a message to the Worker is very simple.</p>

<div class="wp_codebox"><table><tr id="p278041"><td class="code" id="p2780code41"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Message sent by the main page to the Worker. */</span>
arithmeticWorker.<span style="color: #660066;">postMessage</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Main says...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>The message can be a simple variable or a JSON object. The same event management applies to the Worker file. Whenever the main page posts a message to the Worker the Worker can receive the message in a &#8216;onmessage&#8217; event handler, at the same time the Worker can post a message to the main page with the &#8216;postMessage&#8217; method.</p>

<div class="wp_codebox"><table><tr id="p278042"><td class="code" id="p2780code42"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Message sent by a Worker to the main page. */</span>
postMessage<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Worker says...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>We have already seen the Worker code. Below is the code for the main file.</p>

<div class="wp_codebox"><table><tr id="p278043"><td class="code" id="p2780code43"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;x&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;2&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;y&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;3&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;output&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>br <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;multButton&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Multiply&quot;</span> <span style="color: #339933;">/&gt;</span>
<span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;button&quot;</span> id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;addButton&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Add&quot;</span> <span style="color: #339933;">/&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #009966; font-style: italic;">/* Check if Web Workers are supported */</span>
<span style="color: #003366; font-weight: bold;">function</span> getWebWorkerSupport<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: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>Worker<span style="color: #009900;">&#41;</span> <span style="color: #339933;">!==</span> <span style="color: #3366CC;">&quot;undefined&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>getWebWorkerSupport<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> x<span style="color: #339933;">,</span>y<span style="color: #339933;">,</span>message<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009966; font-style: italic;">/* Create a new worker */</span>
    arithmeticWorker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Worker<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;arithmetic.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/* 
       Add a event listener to the worker, this will
       be called when the worker posts a message.
    */</span>
    arithmeticWorker.<span style="color: #660066;">onmessage</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;output&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span> <span style="color: #339933;">=</span> event.<span style="color: #660066;">data</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009966; font-style: italic;">/* Register events for buttons */</span>
    document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;multButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onclick</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: #009966; font-style: italic;">/* Get the values to do operation on */</span>
        x <span style="color: #339933;">=</span> parseFloat<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;x&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        y <span style="color: #339933;">=</span> parseFloat<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;y&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        message <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #3366CC;">'op'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'mult'</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'x'</span>  <span style="color: #339933;">:</span> x<span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'y'</span>  <span style="color: #339933;">:</span> y
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        arithmeticWorker.<span style="color: #660066;">postMessage</span><span style="color: #009900;">&#40;</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;addButton&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">onclick</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: #009966; font-style: italic;">/* Get the values to do operation on */</span>
        x <span style="color: #339933;">=</span> parseFloat<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;x&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        y <span style="color: #339933;">=</span> parseFloat<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;y&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        message <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #3366CC;">'op'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'add'</span><span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'x'</span>  <span style="color: #339933;">:</span> x<span style="color: #339933;">,</span>
            <span style="color: #3366CC;">'y'</span>  <span style="color: #339933;">:</span> y
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        arithmeticWorker.<span style="color: #660066;">postMessage</span><span style="color: #009900;">&#40;</span>message<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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h4>Terminating Web Workers</h4>
<p>Once the main page starts a Worker thread, the thread doesn&#8217;t terminate by itself. The calling page has to explicitly ask the Worker to terminate. This may become necessary because creating each new Worker consumes precious browser resources, which you will need to reclaim once the Workers task is no longer required.</p>

<div class="wp_codebox"><table><tr id="p278044"><td class="code" id="p2780code44"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Terminate the Worker */</span>
arithmeticWorker.<span style="color: #660066;">terminate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Workers and DOM accessibility</h4>
<p>Due to the threading nature of Workers they do not have access to the following JavaScript objects.</p>
<p>    * The DOM (it&#8217;s not thread-safe)<br />
    * The window object<br />
    * The document object<br />
    * The parent object</p>
<p><a href="http://www.codediesel.com/demos/workers/"target="_blank" >VIEW DEMO</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/javascript/introducing-html5-web-workers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encode your email links to prevent spam</title>
		<link>http://www.codediesel.com/security/encode-your-email-links-to-prevent-spam/</link>
		<comments>http://www.codediesel.com/security/encode-your-email-links-to-prevent-spam/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 10:29:25 +0000</pubDate>
		<dc:creator>sameer</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.codediesel.com/?p=2771</guid>
		<description><![CDATA[One of the popular ways to hide your email on a web page from spam bots is to display the email as an image or to use the &#8216;[at]&#8216; word instead of the &#8216;@&#8217; sign. The code given here is yet another way to fight spam. The below function will let you to encode email [...]]]></description>
			<content:encoded><![CDATA[<p>One of the popular ways to hide your email on a web page from spam bots is to display the email as an image or to use the &#8216;[at]&#8216; word instead of the &#8216;@&#8217; sign. The code given here is yet another way to fight spam. The below function will let you to encode email or other links to their equivalent HTML entity encoded syntax. This will enable you to hide your web-page emails from spam bots. As the browser converts and displays the appropriate string from the encoding the user will be able to correctly see the email id, but a spam bot will have a difficult time to decode the encoded string. Of course we now have quite sophisticated crawlers that can work around this types of encoding, but for other crawlers that rely on regular expressions or other such simple methods, they will find it difficult to grab the email links from the page.<br />
<span id="more-2771"></span></p>
<h4>Encoding HTML characters</h4>
<p>The function is quite simple. It encodes email, links or other string characters to their &#8216;Numeric character references&#8217;. For example &#8216;<strong>code</strong>&#8216; will be encoded to <strong>&amp;#99;&amp;#111;&amp;#100;&amp;#101;</strong> &#8211; a decimal encoding or <strong>&amp;#X63;&amp;#X6f;&amp;#X64;&amp;#X65;</strong>  &#8211; a hexadecimal encoding.<br />
The function randomly encodes a character to a <em>hex</em> or <em>decimal</em> representation, so each page refresh will encode the same string to a different format.</p>

<div class="wp_codebox"><table><tr id="p277147"><td class="code" id="p2771code47"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> encodeString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$enc_email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">srand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;"># Convert each character to decimal or hex representation
</span>    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$enc_email</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&amp;#&quot;</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$enc_email</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&amp;#X&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">dechex</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">ord</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000088;">$enc_email</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">echo</span> encodeString<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;designhouse@host.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This will convert the email &#8216;designhouse@host.com&#8217; to</p>

<div class="wp_codebox"><table><tr id="p277148"><td class="code" id="p2771code48"><pre class="text" style="font-family:monospace;">&amp;#100;&amp;#101;&amp;#X73;&amp;#X69;&amp;#X67;&amp;#X6e;&amp;#104;
&amp;#X6f;&amp;#X75;&amp;#115;&amp;#101;&amp;#64;&amp;#X68;&amp;#111;
&amp;#X73;&amp;#116;&amp;#X2e;&amp;#99;&amp;#111;&amp;#109;</pre></td></tr></table></div>

<p>As it uses a random base (decimal or hex), the actual results may differ from yours.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.codediesel.com/security/encode-your-email-links-to-prevent-spam/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

