Facebook like to see content

Started on the old forum in October 2015 · view the original in the archive · old links redirect here

5 replies · 311 views · started 11 years ago · 1 min read

4 participants
arnage Lead · 811 posts #1

I would like to add this on one page...

So when visitor opens that page on a site first to be asked to like Facebook page and than he will see the content, if logged in Facebook. And if not, to be asked to loggin and click like button.

Any idea how to do this?

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
kevk3v Senior · 332 posts #3
  1. Include the JavaScript SDK on your page once, ideally right after the opening <body> tag. You can get an app ID here https://developers.facebook.com/​
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_GB/sdk.js#xfbml=1&version=v2.5&appId=APP ID";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script> 
  1. Add a like button code to your page
<div class="fb-like" data-href="http://coding-talk.com/" data-layout="button_count" data-action="like" data-show-faces="true" data-share="false"></div>
  1. Create a like callback function
<script type="text/javascript">
var page_like = function(url, html_element) {
  alert(url+' Liked!');
//here you can do something like $('#hiddencontent').show();
}
// In your onload handler
FB.Event.subscribe('edge.create', page_like);
</script>

Mobile chat, iphone chat, android chat, chat, rooms http://www.aiochat.com

arnage Lead · 811 posts #4

I guess so too, its a bit confusing docs there...

Thanks Kev. If it comes into play i'll check this out.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
something else Fellow · 2,296 posts #5

A little more help:

Using: $('#hiddencontent').show(); Content you wish to stay hidden would have to be in id="hiddencontent" with css: #hiddencontent{ display: none; }

eg:

<div id="hiddencontent" style="display: none;">
Content you dont want seen here
</div>
👍 1
Share
arnage Lead · 811 posts #6

Ok, thanks. Sorry for late answer.

<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close