Skip to content

Instantly share code, notes, and snippets.

Created July 24, 2017 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a057b324ec159123477e61b94d8375ca to your computer and use it in GitHub Desktop.
Save anonymous/a057b324ec159123477e61b94d8375ca to your computer and use it in GitHub Desktop.
// Функиция которая читает и записывает в куки
<script>
function checkCountry() {
var country = $.cookie("ad_country");
if ( country === undefined || country === "error" ) {
$.jsonp({
type: "GET",
url: "http://ipinfo.io",
callbackParameter: 'callback',
dataType: "jsonp",
timeout: 10000,
success: function(json){
$.cookie("ad_country", json.country, {expires: 7} );
},
error: function(){
$.cookie("ad_country", "error", {expires: 7} );
}
});
}
return country;
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment