无法使地理位置脚本工作
Cannot get Geolocation script to work
我编写了以下代码的脚本,但由于某些原因,它不起作用,请帮助
<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);
})();
相关文章:
- 如何在加载img后强制脚本工作
- 脚本工作,但永远不要启动它
- 信用链接无法根据给定的脚本工作
- 无法使地理位置脚本工作
- fadeln脚本工作不正常
- Firefox 插件生成器 - 无法让内容脚本工作
- Rails 4 turbo-link 阻止 jQuery 脚本工作
- 一个脚本阻止第二个脚本工作
- jQuery脚本工作在Firefox和Coda (IDE),但不是Chrome
- 为什么我不能让这个JS脚本工作?
- Node.js脚本工作一次,然后失败
- Chrome用户脚本工作在一个线程页面,但不是在一个主要的论坛页面,具有相同的结构
- JavaScript和CakePHP:如何让这个简单的脚本工作
- 我的脚本工作与当前的jquery 1.11.1,但不与1.7.1.为什么
- 不能让AJAX脚本工作
- 客户端脚本工作没有查询字符串
- JQuery -脚本工作在所有除了IE10
- JavaScript表单脚本工作Chrome,但没有其他地方
- 脚本工作在Chrome,但不是IE
- HTML -脚本工作在JSFiddle,但不是当我单独运行脚本