无法使地理位置脚本工作

Cannot get Geolocation script to work

本文关键字:脚本 工作 地理位置      更新时间:2023-09-26

我编写了以下代码的脚本,但由于某些原因,它不起作用,请帮助

<script>
    $.getScript('http://www.geoplugin.net/javascript.gp', function() {
    $location =  geoplugin_countryCode();
$location2 = geoplugin_continentCode();        

    if($location == "CA" || $location == "US" || $location2 == "EU" || $location2 == "DE" || $location2 == "FR" || $location2 == "GB") {
    alert($location);
         var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9240923-27']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
    } else {
         var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9240923-27']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
    } 
});

        </script>

这还不是一个正确的答案,因为还不清楚实际问题是什么,但为了向OP解释,我将把它作为答案发布。

$.getScript('http://www.geoplugin.net/javascript.gp', function() {
    $location =  geoplugin_countryCode();
    $location2 = geoplugin_continentCode();        
    if($location == "CA" || $location == "US" || $location2 == "EU" || $location2 == "DE" || $location2 == "FR" || $location2 == "GB") {
       alert($location);
    }
});
/* 
 * I'm not sure what you want to accomplish 
 * with loading Google Analytics within the success 
 * callback of getScript, so I moved it out here until that is clarified.
 */
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-9240923-27']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();