title: Get country code using javascript
body: <p>I can't figure out how to get a country code from a visitor that goes to my webpage. I have seen plenty of other examples but none use plain Javascript. Here is my current code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en-US"&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;script type="text/javascript"&gt;
          var userip;
      &lt;/script&gt;
      &lt;script type="text/javascript" src="https://l2.io/ip.js?var=userip"&gt;       &lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
          document.write("IP: ", userip);
  
          $.get("http://ipinfo.io/"+userip.text(), function (response) {
              reg.text("country code here" + response.country);
          }, "jsonp");
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I get the user's IP addrress from a JSONP request to <code>ipinfo.io</code> using the <code>$.get</code> method of jQuery.</p>
  
  <p>Unfortunately <code>l2.io.js</code> does not return anything other then the ip at this time.</p>
  
  <p>If anyone can help or has any examples please link all related JavaScript libraries that will be needed. Thanks.</p>