Browser geolocation doesn’t work in IE9

I’ve been banging my head for a couple of hours trying to work out why W3C geolocation was working in Firefox but not IE9. Using the F12 developer tools I was able to step through the javascript and see that it was calling getCurrentPosition(), but nothing would happen at that point – neither the success nor error handlers were called.

Various internet suggestions I tried before finally arriving at the answer:

  • Using window.navigator.geolocation rather than just navigator.geolocation. You should do this (or find a toolkit that abstracts it for you – jquery doesn’t seem to).
  • Temporarily changing my DOCTYPE to the HTML5 declaration <!doctype html>. The Microsoft geolocation pages say that geolocation is only supported in standards mode, and that using the HTML5 doctype is the easiest way to do this. However, I could see from F12 developer tools that I was already in IE9 standards mode.
  • Changing the IE9 privacy settings. There’s a checkbox to prevent sites from requesting your location; it wasn’t checked, but there’s a “Clear sites” button next to it so I gave that a go. No dice.
  • Combing through the security settings to see if there was a magic radio button. Nope.

Finally, I created a minimal page on my desktop with just a hyperlink to invoke getCurrentPosition(). That worked, so I assumed there was something subtly broken in my real page. So, I saved the source to the desktop so I could start butchering it to find the problem. However, when I loaded the unmodified page in IE9, it worked.

So I figured it was something to do with the page’s URL. It was being served on an intranet server, so I used the old trick of using a qualified domain (http://foo.internal rather than http://foo) to trick IE into thinking it was an internet site (it seems that dots in the domain are how IE decides). Lo and behold, that did it, and geolocation started working.

However, that wasn’t the end of the story. It turns out that when IE9 prompts you to ask whether you want to share your location, if you click the ‘X’ close button rather than making a selection, it will no longer prompt you thereafter. Restarting the browser clears it. I then went back to my unqualified domain, and that fixed that too.

TL;DR: try restarting your browser.




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: