Mobile Browser Hack – Android, WebKit and Javascript/AJAX Trim() Functions!

Here’s a quick note on mobile browsers like Android, WebKit. Based on my testing, it seems that string trim() function is not supported.

I was trying to do something like:

if(mystring.trim()==”0″) etc…etc…

That won’t work in mobile browsers for some reason but you can do something like it using match instead:
if(mystring.match(/0/)) etc…etc…

I don’t know exactly why trim() isn’t supported fully on mobile browsers but for those of you who have problems with your website that works on desktop browsers but not on mobile ones, this could possibly be your solution.

For the weirdest reasons, trim() function breaks everything in Android and WebKit.  Don’t ask me why, just don’t use it.  Of course, it’s probably not the most efficient function anyways.  Instead use match() to match whatever you need.

There’s also a great guide on regex for Javascript, which is pretty much same as PHP but maybe slightly different.

Leave a Reply

Your email address will not be published.

Other interesting stuff at , , , , , , , ,
Check out more interesting categories: DIY, Featured, Featured Hacks, Featured Web, Hack, Web, WebApp.

Related News and Resources