检查用户是否阻止第三方域 [英] Check if user is blocking 3rd party domain

查看:118
本文介绍了检查用户是否阻止第三方域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一个问题,其中很多我们的支持电话是关于我们的图片未加载,因为用户正在阻止亚马逊s3或类似的第三方服务。我使用第三方服务来托管图片,视频和一些javascript。有没有办法通过javascript检测客户端是否阻止域,以便我们显示一条消息,而不是用户联系支持?

I have run into an issue where a lot of our support calls are about our images not loading because the user is blocking amazon s3 or a similar 3rd party service. I use 3rd party services for hosting images, video, and some javascript. Is there a way to detect through javascript if a client is blocking a domain so that we display a message instead of having the user contact support?

$.ajax 'http://aws.amazon.com/s3/',
  type: 'GET',
  dataType: 'html'
  complete: (e, xhr, settings) ->
    if e.status == 200
      console.log "Not Blocking S3"
    else
      console.log "Blocking S3"

根据我的意见,我尝试了它,但它仍然不工作。

Based on the comments I made an attempt at it, but it is still not working. It returns blocking when I have no blocks.

上面的示例coffeescript代码不工作,因为我相信发生安全错误,因为它在一个不同的域上执行ajax。 Firebug以红色显示请求,但表示为200. e.status正在返回0。

The above example coffeescript code does not work as I believe a security error occurs because it is doing an ajax on a different domain. Firebug shows the request in red, but says 200. e.status is returning 0.

推荐答案

从域中加载图片

<img id="checkImg" src="https://www.google.com/images/srpr/logo3w.pngAAA" />


只是一个常规的图片标签(注意 AAA 到结尾,使工作)。然后你可以检查图片的宽度,看看它是否加载。

​ Just a regular image tag (notice the AAA at the end to make it not work). Then you can check the width of the image to see if it loaded or not.

if(document.getElementById('checkImg').clientWidth != 275)
    alert("Error")

275px宽,但错误图像(在Chrome至少)只有18px。因此,如果图片不是275像素宽,我知道它没有加载。

The Google logo is 275px wide but the error image (in Chrome at least) is only 18px. So if the image is not 275px wide, I know it did not load.

演示

这篇关于检查用户是否阻止第三方域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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