Showing posts with label html5. Show all posts
Showing posts with label html5. Show all posts

Thursday, March 01, 2012

Creating Web Apps in iOS

Lots of ways to make your website/application run as a full screen iOS 'app.' Google the subject and you'll be spoilt for choice.

The biggest problem I had was after I'd finished the basics: created a homepage icon, set the website to be full screen capable (etc). The front page of my web app opened full screen, but as soon as you click on a link (internal or otherwise), mobile Safari is opened for the target page and all the full screen, app-like goodness is gone.

Prevent Mobile Safari Launching

To keep the user inside your iOS 'app' (and not wandering off into the big fat interweb), embed this cheeky little script right at the end of your <body> tag.

<script>(function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(d.href.indexOf("http")||~d.href.indexOf(e.host))&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone")</script>

And this came from a great little discussion at gist.github.com/1042026. It works on iOS 5.

Mobile Checklist

The best checklist I've found for mobifying your site (mainly for iOS and Android) is at html5rocks.com/en/mobile/mobifying/. But the key points are:

  • Create iOS/Android homepage icons - of varying sizes.
  • Embed the relevant META tags to allow the site to render full screen.
  • Optimize your site to take advantage of HTML5 and CSS3 - back to the 90s boys and girls: think of low bandwidth for those truly mobile users.
  • Use media queries to tweak your layout for different screen sizes (and portrait/landscape orientation)
  • Ensure your site design and UI is built around a touchscreen (big, fat buttons and a vertical layout for the really small devices)
  • Keep the user within your app for as long as possible (see above for 'link' issues about preventing Mobile Safari launching).

Friday, February 24, 2012

Embedding Phone Numbers with HTML5 for iOS

Snippet to embed contact data in a web page so that an iOS device can recognise text as a phone number or as contact data. Use the 'itemprop' attribute, although you can also wrap the div in a 'vcard' class, and setting the class of the phone number span to 'tel' seemed to do funky things too:

<div itemscope>
  <span itemprop="name">Rob Carr</span>
  <a class="nowrap" href="mailto:rob@google.com" itemprop="email">rob@google.com</a>
  <span class="nowrap" itemprop="tel">+44 1234 567 890</span>
</div>

I added a 'nowrap' class (white-space:nowrap;) purely for styling and usability. When the name or phone number is clicked on, you get the iOS dialogue box:


Contact info recognition doesn't seem to work on HTML5 desktop browsers, and no idea about whether other mobile devices will recognise the 'itemprop' property.

You can wade through the Microdata spec for HTML5 at http://dev.w3.org/html5/md/, or Google for more examples. HTML5 Doctor always a good read.