测试 URL 是否可从 Web 浏览器访问,即确保未被代理服务器阻止 [英] Test if URL is accessible from web browser i.e. make sure not blocked by Proxy server

查看:27
本文介绍了测试 URL 是否可从 Web 浏览器访问,即确保未被代理服务器阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过 mywebsite.com 为我的网站提供服务.我在 flickr 上托管图像,因此所有图像都通过对 flickr 的获取请求加载到用户的浏览器中.我的许多网站用户都从公司网络访问 mywebsite.com,这会阻止访问 flickr.com.这意味着用户会得到非常烦人的空白占位符而不是图像.我在 Facebook 点赞按钮上遇到了同样的问题.这使我的网站对此类用户没有吸引力.

I am serving my website from mywebsite.com. I host images on flickr so all images are loaded in the user's browser via get requests to flickr. Many of my websites users access mywebsite.com from corporate networks, which block access to flickr.com. This means users get very annoying blank placeholders instead of the images. I get the same problem with the Facebook like button. This makes my site look very unattractive to such users.

有什么方法可以运行客户端脚本来检查 flickr.com、facebook.com 等是否可以访问.如果不是,我可以更改图像的 href 属性以从备用源加载,或者替换为标准图像,说明他们的网络正在阻止访问.我也可以删除 Facebook 的赞按钮.

Is there a way I can run a client side script which will check if flickr.com, facebook.com, etc. are accessible. If not I could change the href attribute of the image to load from an alternate source, or replace with a standard image explaining that their network is blocking access. I could also remove the Facebook like button.

我认为 XML http 请求可以解决问题,但后来我想到了跨域问题.我想我也可以设置一个代理来提供图像,但我不想这样做;这样做的想法是 flickr 占用了带宽.

I thought an XML http request would do the trick, but then I'd hit cross domain issues I think. I guess I could also set up a proxy to serve the images, but I don't want to do that; the idea of this is that flickr takes the bandwidth hit.

TLDR:如何使用客户端技术确定是否可以从用户的浏览器访问 flickr.com.

TLDR: How do I determine if flickr.com is accessible from a user's browser, using client side technology.

推荐答案

你可以试试这个...

var image = new Image();

image.onerror = function() {

   var images = document
                 .getElementById('flicker-images')
                 .getElementsByTagName('img');

   for (var i = 0, imagesLength = images.length; i < imagesLength; i++) {
        images[i].src = 'images/flickr_is_blocked.gif';
   }

};

image.src = 'http://flickr.com/favicon.ico';

Hacky,但它似乎有效.然而,它依赖于 favicon.ico 404ing 意味着主站点是.

Hacky, but it seems to work. However it relies that the favicon.ico 404ing means the main site is.

jsFiddle.

这篇关于测试 URL 是否可从 Web 浏览器访问,即确保未被代理服务器阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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