You need to display certain content for certain countries. Found on this forum such code:

<html> <head> <title>Test GeoIP</title> <script type="text/javascript" src="http://j.maxmind.com/app/country.js"></script> <style type="text/css"> .geoip { display: none; border: 1px solid #036; padding: 10px; margin: 10px; } p { font-size: 0.8em; text-align: center; } </style> <script type="text/javascript"> function init() { var id = geoip_country_code() == 'RU' ? 'country-ru' : 'country-other'; document.getElementById(id).style.display = 'block'; } </script> </head> <body onload="init();"> <div class="geoip" id="country-ru"> <h1>Блок для пользователей из России</h1> </div> <div class="geoip" id="country-other"> <h1>Блок для остальных пользователей</h1> </div> </body> </html> 

The code displays the text “Block for users from Russia” for users from Russia, and “Block for other users” for other countries.

How can I get him to print the text not only for Russia, but, for example, for Belarus, such a text is “Block for users from Belarus”.

I do not understand anything in JS, so if someone can help, then please write a ready-made version or at least understandable. Thank you very much.

  • Usually this is done on the server, in order to "not drag" to other users of the extra countries, a code that they will never see. - ferrari
  • @ Dany994, If you are given an exhaustive answer, mark it as correct (click on the check mark next to the selected answer). - Nicolas Chabanovsky

1 answer 1

Change init() function:

 function init() { var id, country = geoip_country_code(); switch (country) { case 'RU': id = 'country-ru'; break; case 'BY': id = 'country-by'; break; default: id = 'country-other'; } document.getElementById(id).style.display = 'block'; } 

Insert in html where you want:

 <div class="geoip" id="country-by> <h1>Блок для пользователей из Белоруссии</h1> </div> 

The idea should work.

UPD. Slightly optimized JS, you can add other countries as well.