Detecting visitors country using Javascript
About
Whilst trying to work out how to show location based ads on my site I thought of a way to do it using just Javascript.
The idea is to detect the location based on their computers time different to GMT.
Implementation
The following code will detect if a visitor is from America:
<script>
var now = new Date();
var off = (now.getTimezoneOffset());
if (off == 240 | off == 300 | off ==360 | off ==400) {
document.write("American ad code");
}
</script>
Further Info
The following image displays the different time zones:
