如果我无法控制外部网站或其内容,是否可以跟踪 iFrame 中的按钮点击?
(非常虚构的例子)如果我有这样的 iframe:
<iframe src="http://www.johnny.com/plugins/like.php?href=http%253A%252F%252Fexample.com%252Fpage%252Fto%252Flike&layout=standard&show_faces=true&width=450&action=like&font&colorscheme=light&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>
最佳答案
如果您询问是否可以在具有您的 iframe 的 HTML 的 DOM 中找到一个按钮,然后向其添加一个 onclick 事件,那么可以,如果您从同一域获得服务的话。
window.parent.getElementById()
会起作用——任何其他 DOM 函数也会起作用。
如果您不在同一个域中,则浏览器不会允许您。它称为跨站点脚本 (XSS),被视为安全违规行为。
如果您在另一个域中,所有者确实添加了您的 iframe,对吗?如果是这样,让他们也添加事件。他们可以传入变量并调用您的 iframe 上的辅助函数。这样他们就可以传递按钮,您可以向其中添加事件。
关于javascript - 在 iframe 中跟踪按钮点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2820353/