简体   繁体   English

订阅iframe(facebook)中的javascript事件

[英]Subscribe to javascript event in an iframe (facebook)

I have an application where I use an iframe for a facebook likebox. 我有一个应用程序,我使用iframe作为facebook喜欢的。

I want to subscribe, in the main page, to the event when the user clicks on the like button in the iframe. 我想在主页面中订阅当用户点击iframe中的like按钮时的事件。

Basically as soon as the user likes the page I want him to be redirected to a page I'll specify. 基本上,一旦用户喜欢该页面,我希望他被重定向到我将指定的页面。

What javascript command can I use? 我可以使用什么javascript命令?

Thanks 谢谢

Unless your parent document is on the same domain as the Facebook Like frame, you can't script into it at all, for security reasons. 除非您的父文档与Facebook Like框架位于同一个域中,否则出于安全原因,您根本无法编写脚本。 This is the Same Origin Policy. 这是同源政策。 It prevents you not only from detecting the click but also from impersonating the user, forcing them to perform actions (such as Liking you) without their consent. 它不仅可以防止您检测到点击,还可以模仿用户,迫使他们在未经他们同意的情况下执行操作(例如喜欢你)。

You can try to place an element on top of the frame to detect clicks, but by intercepting the click you also stop it going through to the frame. 您可以尝试在框架顶部放置一个元素来检测点击次数,但是通过拦截点击,您也可以停止它进入框架。 About the best you can do is detect a hover over the area of the Like button and remove the covering element, allowing the user to click. 关于您可以做的最好的事情是检测悬停在Like按钮区域上方并移除覆盖元素,允许用户单击。 This isn't reliable though since it'll catch all mouseovers. 这不可靠,因为它会捕获所有鼠标。

You can hook this up to the button 您可以将其连接到按钮

onclick = "window.location('www.google.com')"

obviously replacing the URL with yours. 显然用你的URL替换URL。 But you might want to check if that's legal. 但是你可能想检查一下这是否合法。

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

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