简体   繁体   English

如何跟踪 iframe 内的标签?

[英]How to track a tag inside an iframe?

Can I get the advertiser's site url from an AdSense ad iframe that is posted on my site via JavaScript?我可以从通过 JavaScript 在我的网站上发布的 AdSense 广告 iframe 获取广告客户的网站 url 吗?

I tried various ways to access the iframe, but for some reason I couldn't get the link.我尝试了各种方法来访问 iframe,但由于某种原因我无法获得链接。

If you're accessing an iframe of the same site, you can use this to get the document object of iframe.如果您正在访问同一站点的 iframe,您可以使用它来获取 iframe 的document object。

var iframe = document.getElementById('replace with iframe element id');
var iframeDoc = iframe.contentDocument || iframe.contentWindow.document;

However, if the iframe is of other site(this is your case), you cannot access it because it would be cross site scripting(XSS) then.但是,如果 iframe 属于其他站点(这是您的情况),则您无法访问它,因为那时它将是跨站点脚本(XSS)。

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

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