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

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

问题描述

我从mywebsite.com服务我的网站。我在flickr上托管图像,以便通过获取flickr请求将所有图像加载到用户的浏览器中。我的许多网站用户从企业网络访问mywebsite.com,这会阻止访问flickr.com。这意味着用户会变得非常恼人的空白占位符而不是图像。我也遇到了与Facebook一样的按钮问题。这使得我的网站看起来对这些用户来说很不吸引人。



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



我认为一个XML http请求可以做到这一点,但是我认为我会遇到跨域问题。我想我也可以设置一个代理服务图像,但我不想这样做;这个想法是flickr带宽受到打击。

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

  var image = new Image()解决方案

;

image.onerror = function(){

var images = document
.getElementById('flicker-images')
.getElementsByTagName('img ); (var i = 0,imagesLength = images.length; i< imagesLength; i ++){
images [i] .src ='images / flickr_is_blocked.gif';


}

};

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

哈克,但它似乎工作。然而,它依赖于 favicon.ico 404ing表示主站点是。



jsFiddle


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.

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.

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: How do I determine if flickr.com is accessible from a user's browser, using client side technology.

解决方案

You could try this...

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, but it seems to work. However it relies that the favicon.ico 404ing means the main site is.

jsFiddle.

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

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