如何从阻止外部资源prevent客户端? [英] How to prevent the client from blocking an external resource?
本文介绍了如何从阻止外部资源prevent客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的网站,我调用两个API,但似乎的AdBlock阻断那些之一。
On my website I call two APIs but AdBlock seems to blocking one of one of those.
//website cesare.io
$.get("http://ipinfo.io", function(response) {
var l = "39.069100,-11.402732";
$.get("http://api.wunderground.com/api/cbfb6c4b4b980e56/conditions/forecast/alert/q/"+ l +".json", function(response) {
weather = response.forecast.simpleforecast.forecastday[0].conditions.toString();
txt();
});
}, "jsonp");
我发现用户提供禁止跟踪启用获得上述错误。
I found out users with "Disable Tracking" enabled get the error above.
如何从阻塞ipinfo.io API的回调prevent的AdBlock?
How can I prevent AdBlock from blocking the callback of the ipinfo.io API?
我可以知道为什么的AdBlock禁用此API调用的原因是什么?
Can I know the reason of why AdBlock disabled this API call?
推荐答案
作为一个快速和放大器;肮脏的修复尝试添加该HTTP头 http://ipinfo.io :
As a quick & dirty fix try adding this http header to http://ipinfo.io:
Access-Control-Allow-Origin: *
如果您使用Apache,尝试添加此行到您的.htaccess:
If you use apache, try adding this line to your .htaccess:
Header add Access-Control-Allow-Origin "*"
如果您需要一个代理可以用这个PHP脚本:
If you need a proxy you can use this php script:
$url = "http://ipinfo.io/" . $_SERVER['REMOTE_ADDR'] . "/json";
echo file_get_contents($url);
这篇关于如何从阻止外部资源prevent客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文