如何使用javascript定位广告/横幅广告? [英] How can I geo target ads/banners with javascript?

查看:146
本文介绍了如何使用javascript定位广告/横幅广告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你知道有什么办法吗?真实的例子......?



我正在寻找像maxmind或其他人一样的免费服务(我真的不在乎什么)我想要一个不同的广告对于美国访问者。



非常感谢!



2astalavista:您的示例正常。这就是我所做的,它仍然没有用。

 < html> 
< head>
< title> Geo Test< / title>
< script type ='text / javascript'src ='http://www.101greatgoals.com/wp-includes/js/jquery/jquery.js?ver = 1.7.1'>< /脚本>
< script>
$(document).ready(function(){
$ .getJSON(http://smart-ip.net/geoip-json?callback=?,
函数(数据) ){
console.log(data);
var c = data.countryCode;
if(c ==US|| c ==US){
document.getElementById('ddd')。innerHTML ='US';} else {
document.getElementById('ddd')。innerHTML ='Not US';}
/ *
this服务需求ip
var ip = data.host;
alert(ip);
$ .getJSON(http://freegeoip.net/json/\"+ip,
function(data){
console.log(data);
}
); * /
}
);

}) ;?
< / script>
< / head>
< body>
< div id =ddd>< / div>
< / body>
< / html>

不知道它是服务器(亚马逊)还是CDN(cotendo)....

解决方案

我发现了这些:修复包含链接!



现在它有效:)

 < html> 
< head>
< title> Geo Test< / title>
< script type ='text / javascript'src ='http://code.jquery.com/jquery-latest.min.js'>< / script>
< script>
$(document).ready(function(){
$ .getJSON(http://smart-ip.net/geoip-json?callback=?,
函数(数据) ){
console.log(data);
var c = data.countryCode;
if(c ==US|| c ==US){
document.getElementById('ddd')。innerHTML ='US';} else {
document.getElementById('ddd')。innerHTML ='Not US';}
}
);

});
< / script>
< / head>
< body>
< div id =ddd>< / div>
< / body>
< / html>


Do you know of any way to do it? real example...?

I am looking for a free service like maxmind or others (I really don't care what) and I would like to have a different ad for US visitors.

Thanks a lot!

2astalavista: Your example works fine. This is what I did and it's still not working.

<html>
<head>
<title>Geo Test</title>
<script type='text/javascript' src='http://www.101greatgoals.com/wp-includes/js/jquery/jquery.js?ver=1.7.1'></script>
<script>
$(document).ready( function() {
    $.getJSON( "http://smart-ip.net/geoip-json?callback=?",
        function(data){            
            console.log(data);
            var c = data.countryCode;
            if(c=="US" || c=="US" ){
                document.getElementById('ddd').innerHTML = 'US'; } else {
                    document.getElementById('ddd').innerHTML = 'Not US';}
            /*
            this service needs ip
            var ip = data.host;
            alert(ip);
            $.getJSON( "http://freegeoip.net/json/"+ip,
                function(data){
                    console.log(data);
                }
            );*/
        }
    );

});?
</script>
</head>
<body>
<div id="ddd"></div>
</body>
</html>

Don't know if it's the server (amazon) or the CDN (cotendo)....

解决方案

I found these: http://freegeoip.net/static/index.html and http://smart-ip.net

example:

$.getJSON( "http://smart-ip.net/geoip-json?callback=?",
    function(data){
        var c = data.countryCode;
        if(c=="US" || c=="USA" )
            alert("American visitor!");else
                alert("Not american visitor! ("+c+")");
    }
);


Why is your code not working?

1) You should take care of the error messages:

Uncaught SyntaxError: Unexpected token ? 

remove ?

2) error again:

Uncaught TypeError: Property '$' of object [object Window] is not a function 

this means jquery does not work for some reason.

fix include link according to this!

now it works :)

<html>
<head>
<title>Geo Test</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-latest.min.js'></script>
<script>
$(document).ready( function() {
    $.getJSON( "http://smart-ip.net/geoip-json?callback=?",
        function(data){            
            console.log(data);
            var c = data.countryCode;
            if(c=="US" || c=="US" ){
                document.getElementById('ddd').innerHTML = 'US'; } else {
                    document.getElementById('ddd').innerHTML = 'Not US';}
        }
    );

});
</script>
</head>
<body>
<div id="ddd"></div>
</body>
</html>

这篇关于如何使用javascript定位广告/横幅广告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆