无法获取地理定位脚本 [英] Cannot get Geolocation script to work
本文介绍了无法获取地理定位脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我脚本化了下面的代码,但由于某种原因,它不起作用,请帮忙谢谢
I scripted the following code, but for some reason it does not work please help thanks
<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解释,我会将其作为答案张贴。
This is not a proper answer yet, as it is still unclear what the actual problem is, but to explain to OP, I'll post this as an answer.
$.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);
})();
这篇关于无法获取地理定位脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文