javascript - GeoIP redirect - loading after DOM ready -


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 please let me know how amend code calls freegeoip server after dom ready (after page load).

the freegeoip server not respond blocks page rendering , , tools such gtmetrix/webpagetest show loading times of 1-2 minutes when freegeoip server not responding.

include jquery library , 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> 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -