documentcloud / documentcloud-pages

Responsively embed DocumentCloud pages.
https://documentcloud.github.io/documentcloud-pages/examples/
MIT License
22 stars 10 forks source link

Report iframe parent's URL with pixel ping #38

Closed reefdog closed 8 years ago

reefdog commented 8 years ago

While we don't offer iframe embeds yet, people can and do stick embeds in their own iframes. In this case, pixel ping reports the iframe's URL, rather than the enclosing parent's URL, as the source.

We need to reach out of the iframe and suss out the parent's URL as best we can. Known limitations:

  1. Thanks to same-origin policies and deployment realities, we can't reach out via window.top or window.parent. Apparently the specs say we should be able to, but browsers don't actually let us. Thus, we can only reliably reach up one iframe level, not all the way to the top.
  2. If we use document.referrer as suggested, then any in-frame navigation breaks the referrer link to the parent page.