简体   繁体   中英

Redirect to new page on Facebook Like in Ruby on Rails

What I'd like to accomplish is to have some content available to a user when they hit the facebook 'like' button on my page.

This could either redirect them to a new page or just display new content on the same page, I'm not too picky about that and I don't really care if it's not entirely secure (if someone happens to know the url to the new page and goes to it without hitting 'like' first it is not the end of the world).

I am using the FB like button in an iframe. I have tried just turning the whole iframe into a link but that doesn't seem to work when the iframe has that sort of content. I think the appropriate solution would be to check if the user has liked the page already, and if so, show the new content or whatever. This seems to have been solved in php but that won't work for me. From my understanding I believe that if I have a ROR app then php won`t work but javascript will? I tried looking for a javascript to accomplish this but that seemed to not work for me.

Any help would be greatly appreciated. In case you need it, the iframe:

<iframe src="http://www.facebook.com/plugins/like.php?app_id=107070462729449&amp;href=www.fureelmusic.com&amp;send=false&amp;layout=button_count&amp;width=40&amp;show_faces=false&amp;action=recommend&amp;colorscheme=light&amp;font&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;" allowTransparency="true"><a href="http://www.facebook.com/fureelmusic" target="blank">inside of the iframe i am inside</a></iframe>

You'll need to use the facebook javascript api, and subscribe to the "edge.create" event . Once you've done that, you can do a redirect in the callback you attach.

This cannot be done with IFRAME version of Like Button.

While you may use FB.Event.subscribe to subscribe for edge.create / edge.remove events they only be fired for HTML5 and XFBML versions of Like Button.

Citing Like Button documentation :

There are two Like button implementations: XFBML and Iframe. The XFBML (also available in HTML5-compliant markup) version is more versatile, but requires use of the JavaScript SDK. ..., gives you the ability (through the Javascript library) to listen for like events so that you know in real time when a user clicks the Like button, and it always gives the user the ability to add an optional comment to the like. ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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