RSS

Tag Archives: html5

Placeholder Input Field for Non-HTML5 (with jQuery)

Hagenburger has a very nice fix, with jQuery, for placeholder input that will work for all other non-html5-supported browser. You know, the placeholder text is the input field that has text like “Search…” but will will be gone when the input field is on focus.

The fix actually utilize the placeholder attribute of input tag, so after implementing Hagenburger‘s jQuery, the placeholder text will work in pretty much all browsers, old and new.

HTML5 Input Placeholder Fix With jQuery

 
Leave a comment

Posted by on July 23, 2011 in General

 

Tags: , ,

Geolocation in HTML5

HTML5 supports geolocation with its Geolocation API. The geolocation in HTML5 centered on global object called navigator, specifically navigator.geolocation.

Here’s the code to display geolocation:

function GetLocation()
{
    navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
}

However, the geolocation is only supported in modern browser and the code above doesn’t check for browser’s geolocation support. That being said, there is no error handling if browser doesn’t support geolocation. To implement error handling, we can use Modernizr.

The above code is based on W3C standard and supported by modern browser, so there is no need to reference external javascript file. There is another geolocation api that is open source, it’s called Geo.JS.

Geo.JS is MIT-licensed JavaScript library. To use Geo.JS, you will have to reference to two files:
gears_init.js – can be downloaded fromĀ http://code.google.com/apis/gears/gears_init.js
geo.js – can be downloaded from http://code.google.com/p/geo-location-javascript/

Geo.JS API usage is similar to W3C Geolocation API, it’s written in aligned to W3C standard. The advantage compare to W3C Geolocation API is that Geo.JS supports error handling. Here’s my code:

function GetLocation()
{
    if (geo_position_js.init())
    {
        navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
    }
}

By calling geo_position_js.init(), we initiated the API. The code will also return false if geolocation is not supported by the browser.

 
1 Comment

Posted by on May 8, 2011 in General

 

Tags: , ,

 
%d bloggers like this: