Javascript 无法使地理位置脚本正常工作

Javascript 无法使地理位置脚本正常工作,javascript,geolocation,google-analytics,Javascript,Geolocation,Google Analytics,我编写了以下代码的脚本,但由于某些原因它不起作用,请帮助,谢谢 <script> $.getScript('http://www.geoplugin.net/javascript.gp', function() { $location = geoplugin_countryCode(); $location2 = geoplugin_continentCode(); if($location == "CA" || $location

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

<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>

$.getScript('http://www.geoplugin.net/javascript.gp,函数(){
$location=geoplugin_countryCode();
$location2=geoplugin_CODE();
如果($location==“CA”| |$location==“US”| |$location2==“EU”| |$location2==“DE”| |$location2==“FR”| |$location2==“GB”){
警报(地点);
var _gaq=_gaq | |[];
_gaq.push([''设置帐户','UA-9240923-27']);
_gaq.push([''u trackPageview']);
(功能(){
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);
})();
}否则{
var _gaq=_gaq | |[];
_gaq.push([''设置帐户','UA-9240923-27']);
_gaq.push([''u trackPageview']);
(功能(){
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);
})();
} 
});

这还不是一个正确的答案,因为还不清楚实际问题是什么,但为了向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);
})();

你怎么说它不起作用?发生了什么?你期望会发生什么?它没有显示在谷歌分析我不知道我明白你想在这里完成什么。您正在if和else子句中加载分析?为什么不在if语句之后执行呢?为什么要在
getScript
的成功回调中加载Google Analytics?1分析代码将被修改2。你能解释一下吗:最好举个例子,我给你的问题贴了一个答案,概述了我写这段代码的方式。因为我不知道在成功回调中加载Google Analytics想要实现什么,所以您需要解释一下您想要实现什么。