From the course: HTML5: Geolocation
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Detecting geolocation support - HTML Tutorial
From the course: HTML5: Geolocation
Detecting geolocation support
Detecting support for HTML5 geolocation is fairly simple: we just need to test for the presence of the geolocation object. This is 01-detecting.html from the Chapter 02 folder of your exercise files, and you will notice it's got just this little bit of JavaScript right there and this little bit of HTML. So what happens is when the page gets loaded this onload gets fired and init gets called and init calls getgeolocation, and getgeolocation is the place where we test for the navigator.geolocation object. And if that's found then we return that object and it gets set in this global geo variable; and if not then we return the undefined value. So let's go ahead and run that in the browser. Click on that there, and there it is: "HTML5 Geolocation is supported." So that's the message that's right here, "HTML5 Geolocation is supported." Just to test it, sometimes what I will do is I misspell something on purpose. I will just put that put that x in there and save that and when I load that…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.