blazeworx / flagstrap

A lightwieght jQuery plugin for creating Bootstrap 3 compatible country select boxes with flags
http://blazeworx.github.io/flagstrap
MIT License
88 stars 62 forks source link

Auto select current country #34

Open borisNG opened 6 years ago

borisNG commented 6 years ago

is it possible to pre-select user's country based on an external ip provider like https://ipinfo.io/pricing ?

Saffarnejad commented 5 years ago

You can get the user's country code through the following code:

$(document).ready(function () { var url = "https://ipinfo.io/country"; $.get(url, function (countryCode) { alert(countryCode); //For example show "IR" }); });

Then pass the value to the input before loading the page:

data-selected-country="IR"