Tomomi Imura
July 16, 2011
America discovered the first mobile web
... years after the rest of the world did
wap.yahoo.com (later m.yahoo.com)
for future phones and smart phones
WAP (Wireless Application Protocol)
fetches web contents thru a proxy server that compress, cache and re-format
Webkit
Gecko
Presto
More
http://en.wikipedia.org/wiki/File:Mobile_Web_Standards_Evolution_Vector.svg
<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml" >
<wml>
<card id="order" title="Inventory">
<p>
<select name="Items" title="Items">
<option value="1">Books</option>
<option value="2">Music</option>
</select>
</p>
<do type="accept" label="Query">
<go method="post" href="...">
...
</do>
</card>
</wml>
<input name="zip" format="NNNNN"/>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.2//EN" "http://www.openmobilealliance.org/tech/DTD/xhtml-mobile12.dtd">
<input type="text" style='-wap-input-format: "5N"'/>
<input format="5N"/>
<a> tel and sms protocols
<a> does more than hyperlink and email:
Initiate a phone call
<a href="tel:+18005555555">Order Pizza Now!</a>
Initiate texting
<a href="sms:+18005555555?body=Hello">Text me!</a>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" ...>
"Graceful degradation" to "Progressive enhancement"
456 Bereastreet: http://www.456bereastreet.com/archive/201004/html5_input_types
<input type="number"> <input type="email"> <input type="tel"> <input type="url"> <input type="date"> <input type="search">
<input type="text" required>
<input type="text" readonly>
<input type="text" autocomplete="off">
<input type="text" placeholder="yourname@email.com">
<input type="text" pattern="[0-9]{5}">
<input type="text" autocapitalize="off"> <input type="text" autocorrect="off">
<link rel="stylesheet" type="text/css" media="handheld" href="m.css">
<meta name="viewport" content="width=device-width"/>
@media all and (max-width: 600px) {
body {// extra styles for mobile}
}
@media all and (min-width: 600px) {
body {// extra styles for desktop}
}
Blackberry (4.6+)
<meta name="HandheldFriendly" content="true">
Windows Mobile (6.5)
<meta name="MobileOptimized" content="240">
HTML <link> media Attribute
<link media="only screen and (min-width:680px)">
CSS 3 @media rules
@media all and (min-width:680px) {...}
@media all and (orientation: portrait) {...}
When a browser maps one pixel to one hight DPI screen pixel, text and images become too small
automatically magnify the UI and content (fit to HVGA)
1 CSS pixel != 1 device pixel
Pixel in CSS is relative!!!
So how can I make images look better?
Scale an image with device pixels and not CSS pixels!
iPhone 4 Retina Display
@media only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (min-device-pixel-ratio: 2) {
//some hi-res css}
When the high-DPI devices with a zoom factor of 150% (e.g. 320px to 480px)
Android
@media only screen and (-webkit-min-device-pixel-ratio: 1.5) {...}
Opera Mobile
@media only screen and (-o-min-device-pixel-ratio: 3/2) {...}
DOM property
window.devicePixelRatio
Android users, hit http://girliemac.com/sandbox/viewport.html on your device to see the value!
set the viewport property, target-densitydpi to prevent from scaling pixels
e.g. HDPI WVGA 480x854 Motorola Droid and 480x800 Nexus One.
<meta name="viewport" content="width=device-width, target-densitydpi=device-dpi" />
device-dpi |
use the device's native dpi as target dpi |
low-dpi |
120dpi |
medium-dpi |
160dpi (default) |
high-dpi |
240dpi |
[number] |
70 - 400dpi |
target-densitydpi=device-dpi
@viewport {
width: device-width;
zoom: 1; // NO! This is not THAT zoom you know for IE
user-zoom: zoom;
}
equal to:
<meta name="viewport" content="width=device-width,
initial-scale=1, user-scalable=1">

if (navigator.geolocation) {
// yes, browser supports geolocation. so do something!
navigator.geolocation.getCurrentPosition(successCallback, error);
}
function successCallback(position) {
alert("Latitude: " + position.coords.latitude +
", Longitude: " + position.coords.longitude);
}
W3C Draft: DeviceOrientation Event Specification
Events
deviceorientation compassneedscalibration devicemotion
window.ondeviceorientation = function(event) {
// event.alpha, event.beta, event.gamma
};
<device> element and getUserMedia API proposed by WHATWG
The <device> spec is no longer maintained: http://dev.w3.org/html5/html-device/
getUserMediagetUserMedia and Device Orientation adventures
if (navigator.getUserMedia){
navigator.getUserMedia('video', v_success, v_error);
}
var video_element = document.querySelector("video");
...
function v_success (stream) {
video_element.src = stream;
}
Why not?

Tomomi Imura
http://girliemac.com/blog
@girlie_mac