dougu0824 2015-09-19 01:56
浏览 32
已采纳

检测来自外部域的资源是否在用户端加载[关闭]

I have absolutely no idea if its even possible but its something I'd like to experiment with.

I'd like to be able to detect if a file loads on my site that's being called from another location. The best example I can provide is the following:

I'm able to edit my computers host file to block specific domain names. If I have external.com blocked and mysite.com uses resources from external.com, those resources won't load.

So I'd like to know if there's any way I can detect weather any or all of the resources from external.com are loading when a user visits my site and if possible set up an action to redirect any users that have external.com blocked.

  • 写回答

1条回答 默认 最新

  • dsq1982 2015-09-19 02:12
    关注

    You can't detect if something is specifically blocked - but you CAN check to see whether or not it has successfully loaded by attaching an onload event to an element:

    In HTML:

    <element onload="doSomething()" />
    

    In Javascript:

    object.onload = function(){ //Do Something };
    

    In Javascript attaching an event listener:

    object.addEventListener( 'load', doSomething() );
    

    I would suggest that maybe your 'doSomething()' function could set a flag when particular resources load, then you can check those flags with another function and take whatever action you deem appropriate if anything is missing.

    The only problem is - with regard to your original question - you can't assume that they're blocking resources from blah.com ... only that resources from blah.com failed to load.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码