Saturday 15 May 2010

html - Check if user is using browser located in China or not -



html - Check if user is using browser located in China or not -

(i don't know how) china started block google fonts api, websites include gf need either long time load or aren't beingness loaded. there workaround this, since fonts.useso.com provide same font library (c.f. libs.useso.com, fonts.useso.com respectively).

the next code

<link href='http://fonts.googleapis.com/css?family=open+sans:300,400,600&subset=latin,latin-ext' rel='stylesheet'>

can changed into

<link href='http://fonts.useso.com/css?family=open+sans:300,400,600&subset=latin,latin-ext' rel='stylesheet'>

and work fine in china.

anyway, if website beingness visited people china , europe. need check location of user , load corresponding css depending on if visitor located in china or not.

here's question: can read out user's browser location or should extract user's browser language find out origin? if chinese person visiting website europe? in case should still load google fonts , not useso. ideas on how approach problem?

you utilize 3rd party service determine user location , switch font.

for example, can integrate userinfo.io free. in case, location determined based on ip address if chinese person visits europe, located in europe , google fonts loaded.

insert in <head>:

<script type="text/javascript" href="//cdnjs.cloudflare.com/ajax/libs/userinfo/1.0.0/userinfo.min.js"></script> <script type="text/javascript"> userinfo.getinfo(function(data) { // "data" object contains info if (data.country.code == 'cn') { // load fallback fonts } else { // load google fonts } }, function(err) { // "err" object contains useful info in case of error }); </script>

disclaimer: wrote , maintain userinfo.io

html css fonts geolocation

No comments:

Post a Comment