Suggest a visitor’s region with JavaScript, without an IP lookup

On a past project, we needed to suggest a regional version of a website without using an IP lookup service. A small clue was already available in the browser: its time zone.

This runs entirely in the visitor’s browser. We don’t store or send the detected settings anywhere.

const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

// "Europe/London", "America/New_York", "Asia/Tokyo"…

You can map those values to the markets your website supports, then preselect a region or suggest another edition.

For language, use the browser’s preferences:

const languages = navigator.languages;

// ["fr-FR", "en-GB"]…

Someone can prefer French while using a London time zone, so it helps to treat language and market separately.

The time zone is a device setting, so it’s only a hint about location. I’d use it to suggest a region and let people change it. Both snippets run locally, without an external service or cookies.

Subscribe
Notify of

0 Comments
Oldest
Newest