I'm about to develop a major touch-enabled mobile WebKit application.
I'm looking for any hints or advices about things that differ from a standard desktop-based browser(s).
For example:
on iOS click
events do not propagate upward to the body
element over elements, except for some cases (links, inputs, elements with attached events, etc.).
Android WebKit does not emit events for multi-touch.
I know about these. Are there some other problems? Do you know about some list of known problems?
I've found a few things out in my recent endeavors with the iPad.
1: Version 4.2 iOS has a bug where running too many document.getElementById('foo'); will cause the browser to lag, and thus not execute commands correctly. To remedy this you need to create variables to hold this information and only make the selection commands when needed. Version 4.3 of the iOS does fix this though, as I've tested it on my iPad.
2: When working with positioning, I have found that when creating your own video controller (for html5), if you try and resize the video container by using position: relative or position:absolute, you no longer will see a video, but a nice black screen (with sound!). In order to remedy this, simply target the parent frame and you're good to go.
3: If you're using iScroll be sure to put a timeout on having it load; especially if you have a few other javascripts on the page as even though the document has it loading when 'the page is loaded' via:
// Load iScroll when DOM content is ready.
document.addEventListener('DOMContentLoaded', loaded, false);
I've had this fail, and couldn't figure out for the life of me why my div wasn't sizing correctly showing me all elements but the last two and not scrolling. Instead I simply did a
$(function(){
//other page loaded items to do
//the iScroller init
setTimeout('iScrollerInit();',200);
});
and it fixed the problem very quickly.
4: If you find your clicks aren't quite working correctly, I've found that many of the mobile SDK's out there are binding items on everything, making it difficult to achieve clicks to things normally you want. So to fix this you can do something like:
$("#yourId").unbind("click").click(function(){
//what to do when clicked
});
and I've found this to work most brilliantly.
**UPDATE - Nov 2012 **: It's been a few years, and there is so much more to add to this so wanted to update the list a bit.
5: Javascript is expensive on a handful of devices STILL (December 2012). Doing things that manipulate the DOM generate a good deal of lag on devices and you should be really careful when doing these things. You'll want to make sure to test your Mobile Web pages in both Android older devices and iPhone older devices as from our metrics these are still well used devices.
6: If you are passing HTML to load in a web-view on a device (iPhone App or Android App) there are times when you will see almost a height 0. What you need to do is have your iPhone or Android app make a Javascript call on the actual page targeting a div to check the page offsetHeight which will then allow the webview height to be accurately set.
**UPDATE - Dec 2012 **: Few more awesome findings
7: I've found that when you target your divs for click events that mobile browsers will wait 300ms before firing the event, effectively creating a lag. They do this to confirm the click wasn't a double tap. in order to avoid this you can bind touchend events instead which will fire instantly!
Here's a bit of code
$(document).ready(function() {
$('#element').bind('touchstart', function(event) {
event.stopPropagation();
event.preventDefault();
$(this).toggleClass('hover_heading');
});
$('#element').bind('touchend', function(event) {
event.preventDefault();
$(this).toggleClass('hover_heading');
});
});
Then once you see blinking happening over your items use this to remove that.
body * {
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
Also if you want to check out an outstanding article google wrote on this you can view it here: - Creating Fast Buttons for Mobile Web Applications
**UPDATE - Feb 2013 **: Few more awesome findings
8: When versioning your CSS files and caching them with urls such as: mydomain.com/css/styles.css?v=123 (or something else), be careful on android 2.2 devices and earlier as this forces extremely strange behavior.
From my findings android will render this completely wrong, and force the html to even be messed up. THe best way when working with these older devices is sadly to change the actual file name.
Hopefully these findings help others as I've struggled through each of these problems for multiple hours scratching my head :)
I don't know of a compiled list, but I can list a few:
Just some quick observations.
I recently wrote a blog post about some of the cotchas with using an html5 framework - in my case Sencha Touch to build a native app wrapped in PhoneGap.
http://www.moneytoolkit.com/2011/05/the-problem-with-sencha-touch-and-phonegap/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With