-1

the javascript below redirects based on GEOIP :

<script type="text/javascript">

        var script = document.createElement('script');
        script.src = "//freegeoip.net/json/?callback=nyGeoIP";
        document.getElementsByTagName('head')[0].appendChild(script);
        function nyGeoIP(d) {
            if (d.country_code === 'XX') {
                window.location = 'http://www.domain.com';
            }
        }
        </script>

Can someone please let me know how to amend this code so that it calls the FREEGEOIP server after dom ready (after page load).

The FreeGeoIP server often does not respond which blocks page rendering , and tools such as gtmetrix/webpagetest show loading times of 1-2 minutes when the FREEGEOIP server is not responding.

Ian Kemp
  • 24,155
  • 16
  • 97
  • 121
  • So you want to identify which event is triggered after the page is completely loaded? If so: [window.onload vs document.onload](http://stackoverflow.com/questions/588040/window-onload-vs-document-onload). – mins Apr 26 '15 at 11:09

2 Answers2

0

Include jquery library and use document ready function:

<script type="text/javascript">
$(document).ready(function(){
var script = document.createElement('script');
        script.src = "//freegeoip.net/json/?callback=nyGeoIP";
        document.getElementsByTagName('head')[0].appendChild(script);
        function nyGeoIP(d) {
            if (d.country_code === 'XX') {
                window.location = 'http://www.domain.com';
            }
        }
})

</script>
freethinker
  • 1,838
  • 2
  • 19
  • 44
0

Which JQuery library do I include , currently use only :

1.7.2 1.8.18

the code you provided above does not work