简体   繁体   English

如何检测元素是否在跨域父级的iframe中可见

[英]How to detect if an element is visible within an iframe that is on a cross domain parent

Just as the question states, I have an iframe that is on a cross domain parent. 正如问题所指出的,我有一个跨网域父级的iframe。 I need to trigger an event if that content is scrolled into view or already in view on page load. 如果该内容在页面加载时滚动到视图中或已经在视图中,则我需要触发一个事件。 Normal checks for distance from top/side of page and viewport height/width don't seem to work as they measure the page within the iframe itself. 正常检查距页面顶部/侧面的距离以及视口的高度/宽度似乎不起作用,因为它们在iframe本身中测量页面。

I cannot edit/add anything on the parent page to enable this functionality, everything must be within the iframe itself. 我无法在父页面上编辑/添加任何内容来启用此功能,所有内容都必须在iframe本身内。

The reason behind this is to record whether content has ever had the chance to be viewed by the user or if it was loaded out of view and kept there. 这背后的原因是要记录内容是否曾经被用户查看过,或者是否已被加载到视线之外并保持在那里。

There are companies who provide this service for advertising, but as far as finding out how it is actually done, well it seems to be one of the dark arts. 有一些公司提供这项广告服务,但就弄清楚它是如何完成的而言,这似乎是一门黑手艺。

Any help would be greatly appreciated. 任何帮助将不胜感激。

EDIT: Two examples of the companies I spoke of who offer this service. 编辑:我提到的提供这项服务的公司的两个例子。

  1. View the first tick under (4) http://www.doubleverify.com/what-is-verification/ 查看(4) http://www.doubleverify.com/what-is-verification/下的第一个刻度
  2. First thing they state they can do on the right hand side http://adxpose.com/home.page 他们声明的第一件事是可以在右侧进行操作http://adxpose.com/home.page

spider.io does this probably using browser timing attacks. spider.io可能使用浏览器计时攻击来做到这一点。 there is a video on their page: 他们的页面上有一个视频:

http://www.spider.io/viewability/ http://www.spider.io/viewability/

here is a nice report on how some browser timing attacks work: http://www.contextis.com/documents/2/Browser_Timing_Attacks.pdf 这是有关一些浏览器定时攻击如何工作的不错报告: http : //www.contextis.com/documents/2/Browser_Timing_Attacks.pdf

Simple answer is, you can't . 简单的答案是, 您不能

You have no way to access a cross-domain iframe ( DOM or window object ) with ECMAscript because of the Same Origin Policy. 由于存在相同来源策略,因此无法使用ECMAscript访问跨域iframeDOMwindow object )。

doubleverify and adxpose use "offline" techniques to determine if the ad was visible or not, it doesn't happen on the page view. doubleverify和adxpose使用“离线”技术来确定广告是否可见,它不会在网页视图上显示。 If they did it through Javascript, all you would have to do is look at one of their pixels to see how it works. 如果他们通过Javascript做到了,那么您所要做的就是查看他们的像素之一,看看它是如何工作的。

Are you sure those examples are exclusively iframe based? 您确定这些示例完全基于iframe吗? Maybe they need to add some javascript to the parent Window. 也许他们需要向父窗口添加一些JavaScript。

If you really need this, and 100% accuracy is not needed, I would try some time based techniques on the assumption that most browser will optimize graphical work happening out of view. 如果您确实需要这样做,并且不需要100%的准确性,那么我将尝试一些基于时间的技术,并假设大多数浏览器将优化发生在视图之外的图形工作。

Being realistic I don't think it would be possible to get good results with that techniques in a reasonable time or expecting a general robust cross-browser solution. 现实地说,我认为使用这种技术在合理的时间内无法获得预期的结果,也无法期待使用一个通用的强大的跨浏览器解决方案。 It would be quite fun though. 不过那会很有趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM