<?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>Carsonified &#187; Coding</title>
	<atom:link href="http://carsonified.com/blog/category/mobile/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://carsonified.com</link>
	<description></description>
	<lastBuildDate>Wed, 17 Mar 2010 10:17:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to build mobile widgets</title>
		<link>http://carsonified.com/blog/mobile/how-to-build-mobile-widgets/</link>
		<comments>http://carsonified.com/blog/mobile/how-to-build-mobile-widgets/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 21:46:21 +0000</pubDate>
		<dc:creator>Ryan Carson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Features]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Web Apps]]></category>
		<category><![CDATA[mobile widgets]]></category>

		<guid isPermaLink="false">http://thinkvitamin.com/?p=1178</guid>
		<description><![CDATA[By <strong>Ryan Carson</strong><br />If you&#8217;re a web developer or designer, there&#8217;s a really exciting development happening right now called &#8216;mobile widgets&#8217;. Carsonified is working with Betavine to spread the word about mobile widgets, so we recently spent four days building one in order to see how hard or easy they are to build. The result was Twiggy, a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style=""><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcarsonified.com%2Fblog%2Fmobile%2Fhow-to-build-mobile-widgets%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcarsonified.com%2Fblog%2Fmobile%2Fhow-to-build-mobile-widgets%2F" height="61" width="51" /></a></div><p>If you&#8217;re a web developer or designer, there&#8217;s a really exciting development happening right now called &#8216;mobile widgets&#8217;. Carsonified is working with <a href="http://www.betavine.net/bvportal/web/guest/widgetzone">Betavine</a> to spread the word about mobile widgets, so we recently spent four days building one in order to see how hard or easy they are to build. The result was <a href="http://twiggy.carsonified.com">Twiggy</a>, a Twitter search widget, and today we&#8217;re going to talk about how we built it.</p>
<h3>So what is a mobile widget?</h3>
<p>A mobile widget is a simple web app that&#8217;s built with open web technology like HTML, CSS and JavaScript (we used <a href="http://jquery.com">jQuery</a>). You don&#8217;t have to write a line of Java or any proprietary code and you don&#8217;t have to understand anything about &#8216;mobile development&#8217;. The files are packaged up into a zip file and downloaded to the phone. The device installs the widget locally, and then it can talk to the web. Widgets can currently run on Nokia S60 phones (currently 1M+ and growing).</p>
<p>Widgets have access to a permanent storage facility for settings and downloaded data. This mechanism is similar to cookies, but the storage capacity is larger and does not automatically expire after a given time.</p>
<h3>Why are they a good idea?</h3>
<p>We think mobile widgets are a really good idea because they allow you to reach a huge non-iPhone audience. Don&#8217;t get me wrong, everyone at Carsonified has iPhones and we love The Steve, but we&#8217;re not &#8216;normal&#8217; and as web designers and developers, we have to consider there are a heck of a lot of people out there who would really benefit from useful widgets that ran on their phones. (They also run on Opera.)</p>
<p>Also, you can easily port mobile widgets to iPhone with a few simple tweaks. Here&#8217;s the version of <a href="http://elliottkember.com/twiggy">Twiggy that works on an iPhone</a>.</p>
<p>Here&#8217;s a quick video to show widgets in action, on a Nokia N96:</p>
<p><object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=3565995&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=3565995&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object></p>
<h3>Cold hard cash</h3>
<p>To encourage people to try building mobile widgets, Betavine are <a href="http://www.betavine.net/bvportal/competition/view.html?id=ff8080811f1f3dbb011f3721070438d1">running a competition with a prize of &pound;20,000</a>. There&#8217;s no obligation to Betavine, you keep the IP to the code and they promote the widget to Vodafone customers, so it&#8217;s a pretty nifty deal.</p>
<h3>What&#8217;s in a widget?</h3>
<p>As I mentioned above, a widget is built with HTML, CSS and JavaScript and packaged as a regular zip file, renamed to use the extension .wgt.</p>
<p>Here&#8217;s what&#8217;s in the zip:</p>
<ol>
<li>A widget configuration file. This is an XML file in the root of the widget structure that holds information about your widget including its size, name, author, and security information.</li>
<li>An index document. Like on a web page, this document contains the basic skeleton/content of the widget. Widgets content can be created using any markup that browsers handle natively, for example HTML, SVG, or XML files. This file also lives in the root of the widget structure.</li>
<li>Images. These are contained in a single images folder.</li>
<li>JavaScript files. These are contained in a single script folder.</li>
<li>Stylesheets. These are contained in a single style folder.</li>
</ol>
<p>I&#8217;m going to hand it over to <a href="http://twitter.com/elliottkember">Elliott Kember</a>, who built Twiggy, to go into detail about how Twiggy was built, and what hurdles we had to overcome. Over to you bud &#8230;</p>
<h3>Mobile widget tutorial</h3>
<p>Thanks, Ryan!</p>
<p>Hey everyone, I&#8217;m Elliott and I built Twiggy. I&#8217;m going to take you through a brief walk-through of how to build a widget.</p>
<p>First, you&#8217;ll need a directory. In that directory, make an &#8220;index.html&#8221; file, a &#8220;style.css&#8221; file, a &#8220;scripts&#8221; directory, and an &#8220;images&#8221; directory. You can structure your files any way you feel most comfortable with. If you want to split your CSS files up by contents later on, that&#8217;s fine.</p>
<p>Now, in your HTML file, put some content. For our widget, we&#8217;re using this:</p>
<pre>
<code>
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
  &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;Twiggy&lt;/title&gt;
    &lt;!-- This is for the Opera Widget Emulator. --&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;if(window.parent&amp;&amp;
    parent.emulator)parent.emulator.begin(window)&lt;/script&gt;
    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;
   &lt;/head&gt;
   &lt;body&gt;
  &lt;/body&gt;
&lt;/html&gt;
<!--formatted--></code>
</pre>
<p>You can open it in a browser, and see what it looks like (it should be blank). Now, get a copy of <a href="http://jquery.com">jQuery</a> and put it in your &#8220;scripts&#8221; directory, and add a line like this to your <head> to include it.</p>
<pre>
<code>
&lt;script type=&quot;text/javascript&quot; src=&quot;scripts/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
<!--formatted--></code>
</pre>
<p>Write all your application&#8217;s javascript in an &#8220;actions.js&#8221; file, which goes in your /scripts folder. Add it like this:</p>
<pre>
<code>
&lt;script type=&quot;text/javascript&quot; src=&quot;scripts/actions.js&quot;&gt;&lt;/script&gt;
<!--formatted--></code>
</pre>
<p>If you want to use any other jQuery plugins, drop them in the /scripts folder and include them as normal:</p>
<pre>
<code>
&lt;script type=&quot;text/javascript&quot; src=&quot;scripts/plugin.jquery.js&quot;&gt;&lt;/script&gt;
<!--formatted--></code>
</pre>
<p>Now, add these lines to your &lt;head&gt;, just in case you ever want to look at the page on your iPhone:</p>
<pre>
<code>
&lt;meta name=&quot;viewport&quot; content=&quot;initial-scale=1,
maximum-scale=1,minimum-scale=1 user-scalable=no,width = 320&quot; /&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width;
initial-scale=1.2; maximum-scale=1.2; user-scalable=0;&quot; /&gt;
&lt;meta name=&quot;apple-mobile-web-app-capable&quot; content=&quot;yes&quot; /&gt;
&lt;meta names=&quot;apple-mobile-web-app-status-bar-style&quot;
content=&quot;black-translucent&quot; /&gt;
<!--formatted--></code>
</pre>
<p>They tell the iPhone how to render the page, what level of zoom to use, and basically tell it to treat the page like a web-app.</p>
<p>In your &lt;body&gt;, insert the following divs:</p>
<pre>
<code>
&lt;div id=&quot;home&quot; class=&quot;panel&quot;&gt;
  &lt;form id=&quot;main-search&quot; class=&quot;panel&quot; action=&quot;#&quot;&gt;
    &lt;label for=&quot;search&quot;&gt;What is your name?&lt;/label&gt;
    &lt;input id=&quot;search&quot; /&gt;
    &lt;input type=&quot;submit&quot; id=&quot;bigsubmit&quot; value=&quot;Go!&quot;/&gt;
  &lt;/form&gt;
&lt;/div&gt;
&lt;div id=&quot;results&quot; class=&quot;panel&quot;&gt;
  &lt;!-- result goes in here --&gt;
&lt;/div&gt;
<!--formatted--></code>
</pre>
<p>Inside the body, we&#8217;ve put two divs with class &#8220;panel&#8221;. These are different pages of our application, and only one will show at a time. When we submit the form on the &#8220;home&#8221; panel, we want the home panel to hide, and the &#8220;results&#8221; panel to show.</p>
<h3>The JavaScript</h3>
<p>Now for some actions.js Javascript code:</p>
<pre>
<code>
var search = function(text){
  text = &quot;Hello, &quot;+text+&quot;!&quot;;
  $(&#039;#home&#039;).hide();
  $(&#039;#results&#039;).text(text);
  $(&#039;.panel#results&#039;).fadeIn(&#039;fast&#039;);
  return false;
};

$(&#039;document&#039;).ready(function(){
  $(&#039;#search&#039;).focus();
  $(&#039;#results&#039;).hide();
  $(&#039;#main-search&#039;).submit(function(){
    value = $(&#039;#search&#039;).val();
    search(value);
  });
});
<!--formatted--></code>
</pre>
<p>Rad! We&#8217;ve got ourselves a widget.</p>
<h3>Making it look pretty</h3>
<p>Now let&#8217;s add some style:</p>
<pre>
<code>
*{outline: none !important;}
input::-moz-focus-inner { border: 0 !important; }

html, body {
  padding: 0;
  margin: 0;
}

body {
  display: block;
  width: 100%;
  font-family: verdana;
  background: #007FC0;
  text-align: center;
  color: white;
}

#home.panel {
  padding: 20px 0;
  display: block;
}

#results.panel {
  background: #ff00ff;
}

#search {
  margin-top: 10px;
  padding: 4px;
  border: 1px solid #ff00ff;
  font-size: 13px;
}
</code>
</pre>
<p>And we&#8217;ve got the beginnings of a widget.</p>
<h3>The configuration</h3>
<p>Now, all you have to do is add a config.xml file, which looks like this:</p>
<pre>
<code>
&lt;?xml version=&#039;1.0&#039; encoding=&#039;UTF-8&#039;?&gt;
&lt;widget dockable=&quot;yes&quot;&gt;
  &lt;widgetname&gt;My Awesome Application&lt;/widgetname&gt;
  &lt;description&gt;It asks you your name, and says hi!&lt;/description&gt;
  &lt;icon src=&quot;icon_64.png&quot; /&gt;
  &lt;width&gt;240&lt;/width&gt;
  &lt;height&gt;320&lt;/height&gt;
  &lt;author&gt;
    &lt;name&gt;John Q. Developer&lt;/name&gt;
  &lt;/author&gt;
  &lt;id&gt;
    &lt;name&gt;My Awesome Application&lt;/name&gt;
    &lt;revised&gt;2009-04-08&lt;/revised&gt;
  &lt;/id&gt;
&lt;/widget&gt;
<!--formatted--></code>
</pre>
<p>And you&#8217;ve got it. Feel free to open that in Opera just to test it out.</p>
<h3>Searching Twitter</h3>
<p>Now, if you want to search Twitter, include the plugin from <a href="http://tweet.seaofclouds.com/">tweet.seaofclouds.com</a> after your jquery javascript file:</p>
<pre>
<code>
&lt;script type=&quot;text/javascript&quot; src=&quot;scripts/jquery.tweet.js&quot;&gt;&lt;/script&gt;
<!--formatted--></code>
</pre>
<p>While you&#8217;re there, change your label to:</p>
<pre>
<code>
&lt;label for=&quot;search&quot;&gt;What are you looking for?&lt;/label&gt;
<!--formatted--></code>
</pre>
<p>Change your actions.js file to:</p>
<pre>
<code>
var search = function(text){
  $(&#039;#home&#039;).hide();
  $(&#039;#results&#039;).fadeIn(&#039;fast&#039;);
  $(&quot;#results&quot;).tweet({
              query: text,
              join_text: &quot;auto&quot;,
              avatar_size: 32,
              count: 10,
              loading_text: &quot;loading tweets...&quot;,
              auto_join_text_reply: &#039;&#039;, auto_join_text_default:
              &quot;&quot;, auto_join_text_ed: &quot;&quot;,
              auto_join_text_ing: &quot;&quot;, auto_join_text_reply:
              &quot;&quot;, auto_join_text_url: &quot;&quot;,
  });
  return false;
};

$(&#039;document&#039;).ready(function(){
  $(&#039;#search&#039;).focus();
  $(&#039;#results&#039;).hide();
  $(&#039;#main-search&#039;).submit(function(){
    value = $(&#039;#search&#039;).val();
    search(value);
    return false;
  });
});
<!--formatted--></code>
</pre>
<p>And add this to your CSS:</p>
<pre>
<code>
#results { float: left; display: block; width: 100%; }
ul { margin: 0; padding :0; }

li {
  list-style-type: none;
  text-align: left;
  background: white;
  color: #333;
  line-height: 1.5;
  border-top: 1px solid #007FC0;
  float: left;
  display: block;
  padding: 5px 0;
  font-size: 12px;
  width: 100%;
}

li img {
  float: left;
  display: block;
  margin: 5px 8px 5px 5px ;
}
</code>
</pre>
<p>And you&#8217;re done! Zip everything in that folder up into a file called &#8220;search.wgt&#8221; (zip -r search.wgt *) and put it on your phone via USB cable. When you run it, it&#8217;ll run as a widget.</p>
<h3>Testing with an emulator</h3>
<p>Go get the widget emulator and try it. It should look like this:</p>
<p><img src="http://img.skitch.com/20090408-j1ux25wnxjpsggxxj6ksq3ffej.png"></img><br />
<img src="http://img.skitch.com/20090408-j1ux25wnxjpsggxxj6ksq3ffej.png"></img></p>
<h3>The good, the bad and the ugly</h3>
<p>This is a cool experiment, because you now have a site that will work in just about anything. The iPhone will handle it, it&#8217;ll work as a dashboard slice, browsers like it, and it can be run as a widget. We&#8217;ve tried to port it to a PhoneGap app for the iPhone, but no success yet.</p>
<p>There&#8217;s really not too much to watch out for. You do, however, have to be careful with your 100% width layouts so that the application doesn&#8217;t scroll horizontally.</p>
<p>Here are some other gotchas:</p>
<ul>
<li>Auto-focus input fields wherever logical. Nobody likes using that !$?*! joystick mouse.</li>
<li>Hover effects are important. Make buttons obvious, because getting to them is a nightmare.</li>
<li>Make sure the phone has your typeface, and renders it nicely. I got caught out with italics.</li>
<li>Don&#8217;t resize images with HTML &#8211; although this is pretty good advice anyway. The phone does it wrong, and it looks horrible.</li>
<li>Even if you think you&#8217;re only bundling this on the phones, use CSS sprites &#8211; because once you&#8217;re done, you have a web app waiting to happen, and waiting for your button images to load on hover is lame.</li>
<li>There&#8217;s no keypress-type event handling, which is a damn shame if you&#8217;re making a game. Poll instead.</li>
<li>Remember, the phone is fast, but not as fast as your computer is. Neither is the network connection, so be thrifty.</li>
</ul>
<h3>Data storage for widgets</h3>
<p>Storing stuff on the phone is done through some Javascript API calls. You don&#8217;t have access to anything juicy yet, but you can store and retrieve strings, using the widget.getPreferenceForKey() and widget.setPreference() methods. To be clever, include the jQuery Cookie plugin and do this:</p>
<pre>
<code>
var get_key = function(key){
  if (typeof(widget) != &amp;#039;undefined&amp;#039;){ // A phone!
    return widget.preferenceForKey(key);
  }else{ // It&amp;#039;s a browser!
    return $.cookie(key);
  }
}

var set_key = function(value, key){
  if (typeof(widget) != &amp;#039;undefined&amp;#039;){
    return widget.setPreferenceForKey(value, key)
  }else{
    return($.cookie(key, value));
  }
}
<!--formatted--></code>
</pre>
<p>This way, you can set and get keys without worrying about whether you&#8217;re saving to a cookie, or to the phone. Happy hunting!</p>
<p><em>Elliott is a freelance developer who lives in Bath, and used to work for Carsonified. He writes CSS, uses Rails and is generally available. He also likes long walks on the beach and candle-lit dinners. You can find him at <a href="http://twitter.com/elliottkember">@elliottkember</a> or <a href="http://www.elliottkember.com">elliottkember.com</a>.</em></p>
<img src="http://carsonified.com/?ak_action=api_record_view&id=1178&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://carsonified.com/blog/mobile/how-to-build-mobile-widgets/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Coding for the mobile web</title>
		<link>http://carsonified.com/blog/mobile/coding-for-the-mobile-web/</link>
		<comments>http://carsonified.com/blog/mobile/coding-for-the-mobile-web/#comments</comments>
		<pubDate>Wed, 05 Mar 2008 12:59:29 +0000</pubDate>
		<dc:creator>Chris Mills</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Features]]></category>
		<category><![CDATA[Mobile]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Dev]]></category>
		<category><![CDATA[mobile web]]></category>

		<guid isPermaLink="false">http://www.thinkvitamin.com/features/css/coding-for-the-mobile-web</guid>
		<description><![CDATA[By <strong>Chris Mills</strong><br />Introduction
Good evening &#8212; in this article I will aim to demystify the world of mobile web development, or in other words, developing web sites so that they will provide an acceptable user experience on mobile devices. I&#8217;ll run through how &#8220;the mobile web&#8221; differs from the normal web, the basics of techniques you can employ [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style=""><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fcarsonified.com%2Fblog%2Fmobile%2Fcoding-for-the-mobile-web%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fcarsonified.com%2Fblog%2Fmobile%2Fcoding-for-the-mobile-web%2F" height="61" width="51" /></a></div><h2>Introduction</h2>
<p>Good evening &mdash; in this article I will aim to demystify the world of mobile web development, or in other words, developing web sites so that they will provide an acceptable user experience on mobile devices. I&rsquo;ll run through how &#8220;the mobile web&#8221; differs from the normal web, the basics of techniques you can employ to make your sites work sucessfully on both mobile and desktop browsers, some general DOs and DON&rsquo;Ts for mobile web design, and numerous resources where you can go to find out more information.</p>
<h2>How does the mobile web differ from the normal web?</h2>
<p>This is a good question &mdash; first maybe we should start by answering the question <q>what is the mobile web?</q> after all, there isn&rsquo;t a separate mobile web  that users of mobile devices plug into, leaving the desktop web for when they get home in front of their home computer. When I say <q>mobile web</q>, I mean <q>the Web as viewed through mobile devices.</q></p>
<p>At Opera, we passionately dedicate ourselves to creating browsers that allow you to view the whole web, regardless of (dis)ability or browsing device. There is one and <em>only</em> one web, and you can make this one web work for everyone on every device as long as you treat it with a bit of care and respect and follow web standards when creating your sites. There are exceptions to this rule however &mdash; in some cases separate mobile sites DO make sense, as you&rsquo;ll see below.</p>
<h3>The playing field is not level on mobile</h3>
<p>In the desktop domain, things are getting pretty easy for us web developers these days &mdash; most modern browsers support web standards pretty well, be they Opera, Firefox (and other Gecko-based browsers) or Safari (and other WebKit-based browsers). Even IE is causing us less pain than it used to, although IE 6 is still used by an alarming number of web users, due to factors such as corporate lock in. The story is quite different on mobile devices however:</p>
<ul>
<li>You&rsquo;ve got web browsers that offer support for <q>the full web</q>, like <a href="http://www.opera.com/products/mobile">Opera Mobile</a> and <a href="http://developer.apple.com/iphone/devcenter/">Safari</a> on the iPhone. Opera Mobile uses the same rendering engine as the equivalent desktop version, so the standards support is about the same.</li>
<li>You&rsquo;ve got constrained browsers, ie, browsers with a limited support for web standards. A few of these still only support WAP (such as WinWAP,) some support other standards like cHTML or HTML MP (for example the Japanese NTT DoCoMo iMode browsers,) and some support a limited subset of the web standards (such as Netfront, Pocket IE, and Blazer.)</li>
<li>Lastly, you&rsquo;ve got <a href="http://www.operamini.com">Opera Mini</a>, and other browsers that work via a proxy system. It mainly just acts as a client interface between the user and a big server farm. When the user submits a URL, the client asks the servers to look up the page. They then convert it into a lightweight binary markup language, format it for viewing on a mobile device, and send it back to the client for viewing. The major advantage of doing it this way is that the pages are reduced in size by up to 90%, saving the user lots of money on bandwidth. language  Say what web standards do and don&rsquo;t work well on mobile devices. Because of the way the service is set up, Opera Mini doesn&rsquo;t handle some aspects of Ajax/JavaScript very well &mdash; <a href="http://dev.opera.com/articles/view/javascript-support-in-opera-mini-4/">this is explained in detail here</a>.</li>
</ul>
<p><strong>Note: don&rsquo;t expect your ultra-interactive Ajax and DOM scripting animated sites to work well on mobile devices. JavaScript support on mobile devices varies a lot. Provide fallbacks at all times. An example of this approach is called <a href="http://domscripting.com/blog/display/41">Hijax</a>.</strong></p>
<p>So as you can see, you&rsquo;ve got quite a bit more to think about in terms of cross browser support on mobile devices. But never fear &mdash; my advice below will send you in the right direction, and as time goes on standards support will improve across mobile browsers, to the point where mobile web development isn&rsquo;t really that much of a worry anymore. When will that happen? Who knows!</p>
<h3>What are the other constraints of mobile browsers?</h3>
<p>Of course, there are more considerations when developing web sites that work on mobile devices, besides just mobile browser standards support. You also have to consider the constraints of the device itself, such as:</p>
<ul>
<li>Limited controls &mdash; don&rsquo;t just assume your user can control everything with a mouse, provide a keyboard alternative. Some mobile phone users may not have a mouse pointer equivalent, so constructs like <code>:hover</code> and <code>onClick</code> are useless to them (this is important for accessibility as well &mdash; some users may have disabilities that affect their ability to use their hands.) Also important is providing aids for inputting data &mdash; most of you will already know how annoying it is having to fill in a long web form using a mobile phone. To get around this, try to make as many things as possible selectable from a drop-down list, rather than expecting the user to type it in. Prefilling form fields with the most likely option is also a good idea.</li>
<li>Limited screen size &mdash; think about how usable your beautiful intricate 1024 x 768 design will look like on a 240 x 320 screen, or smaller than that&#8230;there are some ways to plan for this &mdash; you can deliberately make your design very simple and fluid, or you can serve appropriate pages to a mobile device using capability detection or media queries and media types (more on this later.) Some phones will help you out in this regard, with mechanisms such as &ldquo;zoom modes&rdquo;, but you can&rsquo;t guarantee it.</li>
<li>Limited memory and bandwidth &mdash; mobile devices will obviously have less memory available than desktop computers, therefore you need to think carefully about those image heavy galleries, and interactive streaming video applications you we planning on putting on your home page! Again, some mobile browsers have the option of turning images off, but again you can&rsquo;t be sure.</li>
<li>Limited typography &mdash; wow, you thought you had it bad with typography on desktop computers? You &rsquo;aint seen nothing yet! There are exceptions to this rule, but a lot of mobile devices have very limited font choices, like 1 or 2. This is partly down to the system, and partly down to the browser.</li>
<li>Limited colour palette &mdash; some mobile devices also have a very limited palette. Think about how much your page&rsquo;s experience reiles on colour, and make sure that colour contrasts still work ok on mobile devices.</li>
</ul>
<p>It is constraints like these that really make the mobile web experience different from the desktop web experience. Never try to kid yourself that the user experience on your site will be EXACTLY THE SAME on mobile devices as it is on desktop devices &mdash; this isn&rsquo;t going to happen. You do however need to make sure that the experience is still a good one, regardless of browsing device.</p>
<p>The only way to be really sure that your site provides a good mobile experience is to test, test, and test again, on multiple devices. Some web designers have been known to have half a dozen mobile devices at hand to test on, in addition to their normal phone, desktop computers, and game console browsers.</p>
<h2>Different approaches to the problem</h2>
<p>It is generally recognized that there are three ways to approach the mobile development problem (this is corroborated by Cameron Moll &mdash; <a href="http://dev.opera.com/articles/view/free-mobile-web-design-chapter-to-downlo/">check his book out for more</a>.) I&rsquo;d recommend trying to follow way number three if possible &mdash; as stated earlier, at Opera we believe that there should only be one web &mdash; but as I&rsquo;ve also said earlier, there are some case where this is difficult to achieve, and/or unnecessary. the three methods are as follows:</p>
<ol>
<li>Do nothing except follow web standards.</li>
<li>Create a completely seperate mobile site</li>
<li>Create one site, but add code to optimize it depending on the device and browser looking at it.</li>
</ol>
<p>Let&rsquo;s now go through each of these in turn.</p>
<h3>Do nothing except follow web standards and best practices</h3>
<p>The foundation of every good web site is a good HTML structure, with CSS for style and JavaScript for behaviour. If you follow the standards carefully, there is a pretty good chance that most mobile browsers will be able to at least interpret your sites and render them in a manner that is basically usable. For example:</p>
<ul>
<li>A site with good logical source order structure and without decorative images in the markup will display logically in a mobile browser&rsquo;s single column/mobile mode.</li>
<li>If your form elements have <code>label</code> elements then the browser will make more sense of form fields</li>
<li>If you also use good graceful degredation/progressive enhancement techniques for your CSS and JavaScript so that functionality not supported in browsers is either simplified, or ignored and an alternative provided, the chance of the site providing an acceptable user experience is increased greatly.</li>
</ul>
<p>This is not a bad way to go, but there is more that can be done to improve the mobile user experience if you have the time and the knowhow to spend on it. If your target audience includes a great deal of users using either non-HTML browsers (eg Japanese browsers that support WAP or cHTML, then you may be forced to detect for the device and serve up appropriate content.</p>
<h3>Provide a completely separate mobile site</h3>
<p>As mentioned before, I think this way should be avoided if at all possible. You can do device detection and redirect automatically so that it doesn&rsquo;t inconvenience the user base, but it does mean having to maintain two web sites. The main way to do this is to detect the browser via user agent sniffing or capability detection on the server-side, and then serve up the appropriate site. There are a number of good articles at <a href="http://dev.opera.com">dev.opera.com</a> about how to do this &mdash; see the resources section at the end.</p>
<p>But there are exceptions, where a separate mobile site may mke sense &mdash; you&rsquo;ve got to consider the user experience at all times. Some types of browsing device won&rsquo;t be likely to make use of certain web sites, or certain features of certain web sites. For example, take a site such as a university campus that has search functionality for looking up department phone numbers, but also contains pages and pages of university history. You are likely to want to use the former on a mobile device, say if you are meeting someone but can&rsquo;t find their department, but you are unlikely to want to sit and read reams of text on a mobile device while out and about.</p>
<p>In this situation, you could use some of the techniques described below to create a site that only serves a certain subset of it&rsquo;s functionality to mobile devices, or it might just be easier to create a seperate site entirely for mobile devices. You could just detect what kind of device your users have and serve them the appropriate site automatically, making the process completely transparent to the user, but this is seen as bad by many &mdash; many people don&rsquo;t like to be restricted like this, so if you are going to do it, provide a link to the full site so the user can try using it on their mobile browser if they wish.</p>
<p>One word of warning &mdash; device detection is very open to abuse. You often see a full desktop version of a site in all it&rsquo;s glory, and then a really rubbish basic mobile site experience alongside it, because the developer is just dumbing the mobile site down to the lowest common denominator. It&rsquo;s easier on him or her, but not fair on the target audience, as many mobile browsers can handle the full capabilities of the Web these days! You should instead be serving devices with as much capability as they can handle, and taking advantage of mobile specific benefits, such as location based services (LBS), and the <code>tel:</code> protocol, which can cause a mobile phone to dial a phone number when a link is clicked on.</p>
<h3>Provide one site&hellip;</h3>
<p>This is where it starts to get interesting. You can again rely on server-side capability detection, but optimize a single site for the mobile device, rather than redirect to a seperate site. There are databases of mobile phone capabilities availble, such as <a href="http://wurfl.sourceforge.net/">WURFL</a>. This comes in the form of an XML file that you can query to find out the capabilities of a device, before sending it optimized content. You can also query the UA strings of a mobile device to find out details such as whether the device has a camera, what the screen dimensions are, and what languages it would prefer content to be delivered in.</p>
<p>On the client side, you&rsquo;ve got a couple of options for optimizing content for mobile devices &mdash; media types and media queries.</p>
<h4>media types</h4>
<p>As you&rsquo;ll no doubt already know, you can specify different CSS to be used for different purposes, for example:</p>
<pre><code>
<link rel="stylesheet" media="screen" type="text/css" href="main.css" />
<link rel="stylesheet" media="print" type="text/css" href="print.css" />
<link rel="stylesheet" media="handheld" type="text/css" href="mobile.css" /></code></pre>
<p>the <code>handheld</code> media type allows you to target a mobile device with a stylesheet optimized for viewing on mobile devices (eg simplified layout, simplified typography etc.) It is a well-supported mechanism, and fairly simple to implement, but it does have it&rsquo;s drawbacks. Again, it is often abused by developers to serve a site a crappy lowest common denominator layout. So much so in fact, that Opera Mini recently changed it&rsquo;s default behavior from using the <code>handheld</code> stylesheet to using the <code>screen</code> stylesheet. Opera Mini can handle most full web sites, so it doesn&rsquo;t really need to use the <code>handheld</code> stylesheet. You can set Opera Mini to use it instead if you wish by switching to mobile view in the browser preferences.</p>
<h4>Media queries</h4>
<p>Media queries are a CSS 3 construct that act in a similar way to conditional comments &mdash; you can enclose a block of CSS rules inside a media query, and then have them applied to your markup (or not) depending on a condition, such as &ldquo;is the screen size less than 480 pixels&rdquo;? Put into code, this would look something like the following:</p>
<pre><code>img {
  margin: 0 0 10px 10px;
  float: right;
}

@media all and (max-width: 480px) {
  img {
    margin: 10px auto;
    float: none;
    display: block;
  }
}</code></pre>
<p>You could even use a couple of media queries together, as follows:</p>
<pre><code>body {
  max-width:800px;
  font-family:georgia, serif;
}

img {
  margin:0 0 10px 10px;
  float:right;
}

.info {
  position:absolute;
  left:8000px;
}

@media all and (max-width: 480px) {
  img {
    margin:10px auto;
    float:none;
    display:block;
  }
}

@media all and (max-width: 240px) {
  img {
    display:none;
  }
  .info {
    position:static;
  }
}</code></pre>
<p>So in this example (<a href="/images/articles/mobile101/source.zip">source code available here</a>,) images in browsers with a screen width larger than 480 pixels are displayed floated to the right, with the text flowing round them at a co<del class="edit=david">n</del>mfortable distance provided by the margins. (There is an alternative message hidden in <code>p</code> elements with a <code>class</code> of <code>info</code> &mdash; check the HTML source out.) The text flow might start to look a bit crappy on smaller screens, where there isn&rsquo;t enough room to have the images and an appreciable amount of text on the same line, so as soon as the viewport gets smaller than 480 pixels, the images are changed so that they no longer flow the text around them, but are instead displayed on separate lines using <code>display:block</code>. But wait &mdash; there&rsquo;s more! If the screen gets far too small for the images to be displayed usefully, then they disappear, and the alternative messages are displayed in their places, to give textual descriptions of those pictures &mdash; this provides an alternative mechanism of getting that information across to the reader, and also provides a textual alternative for blind users using screenreaders to view the site. Figure 1 shows the three different display settings when the example is viewed in a browser that supports media queries, such as Opera 9.5.</p>
<p><a href="/images/articles/mobile101/figure1.jpg"><img src="/images/articles/mobile101/figure1_small.jpg" alt="The three different viewing modes of the example" /></a></p>
<p>Figure 1: The three different viewing modes of my example.</p>
<p>This sounds great, but what&rsquo;s the downside? Well, browser support is currently very patchy for media queries. Opera browsers support them, so does Safari 3  (and other modern Webkit-based browsers), but Firefox <3 doesn&rsquo;t, and neither does IE or other web browsers. One way to tackle this is to use a combination of media types and media queries. This kind of approach is <a href="http://dev.opera.com/articles/view/how-to-serve-the-right-content-to-mobile/">explained in my article here</a>. It is a workaround of sorts, but certainly not ideal. This should improve in the future.</p>
<h2>Summary</h2>
<p>That&rsquo;s it for now. I hope my journey into the world of mobile development has been helpful. I&rsquo;ve only scratched the surface here, so be sure to dig into some of the resources below to learn more.</p>
<h2>Resources</h2>
<ul>
<li><a href="http://mobilewebbook.com/">Mobile web design book, by Cameron Moll</a></li>
<li><a href="http://dev.opera.com/articles/view/designing-and-developing-mobile-web-site/">Designing and developing mobile web sites in the real world</a> &mdash; a case study by Brian Suda</li>
<li><a href="http://dev.opera.com/articles/view/server-side-capability-detection-for-mob/">Server-side capability detection for mobile devices</a> by Brian Suda (includes more on WURFL, UA strings&#8230;)</li>
<li><a href="http://dev.opera.com/articles/view/javascript-support-in-opera-mini-4/">Ajax/JavaScript support in Opera Mini 4</a>, by me</li>
<li><a href="http://dev.opera.com/articles/view/opera-mini-request-headers/">Kristian von Streng HÃ¦hre&rsquo;s Opera Mini request header reference</a></li>
<li><a href="http://dev.opera.com/articles/view/how-to-serve-the-right-content-to-mobile/">How to serve the right content to mobile browsers</a>, again by my good self &mdash; includes media queries and media types</li>
<li><a href="http://dev.opera.com/articles/view/safe-media-queries/">Creating safe media queries that work cross browser</a></li>
<li><a href="http://dev.opera.com/articles/view/web-design-with-opera-mobile-in-mind/">Web design with Opera Mobile in mind</a>, again by me</li>
<li><a href="http://wurfl.sourceforge.net/">The WURFL homepage</a></li>
<li><a href="http://www.opera.com/products/mobile/">The Opera Mobile homepage</a></li>
<li><a href="http://www.operamini.com/">The Opera Mini homepage</a></li>
</ul>
<p><script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script></p>
<img src="http://carsonified.com/?ak_action=api_record_view&id=1775&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://carsonified.com/blog/mobile/coding-for-the-mobile-web/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
