0

Can someone please explain to me how can I have a download link appear when a user presses the share button on a feed dialog box? I'm using the following code: (with my own information of course)

Post to Feed

<script> 
  FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});

  function postToFeed() {

    // calling the API ...
    var obj = {
      method: 'feed',
      link: 'https://developers.facebook.com/docs/reference/dialogs/',
      picture: 'http://fbrell.com/f8.jpg',
      name: 'Facebook Dialogs',
      caption: 'Reference Documentation',
      description: 'Using Dialogs to interact with users.'
    };

    function callback(response) {
      document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }

    FB.ui(obj, callback);
  }

</script>

I have no clue on how to do is: what code do I need so that when a user clicks "share" a download box appears? But if they click cancel a message pops up telling them they need to share first? I have posted a similar question before and I got an answer saying I need to use some sort of JavaScript but the problem is I don't know how or what to write? Can someone please show and explain the sort of JavaScript I need to me because I don't know how to use JavaScript one bit.

Thanks in advance for any answers/help!!

Rhubarb
  • 71
  • 1
  • 5

1 Answers1

0

The callback function is executed when the user completes the feed post dialog, with either the "share" or "cancel" button. You can test for a "post_id" to see which action the user took. Then either show the download box or display an alert (or perhaps a more user-friendly message format).

Add a hidden download box element to your page with an id of "download_box":

<div id="download_box" style="display: none;">
    Download Box (whatever that means) goes here
</div>

And replace your current "callback" function:

function callback(response) {
    if (response && response.post_id) {
        document.getElementById('download_box').style.display = 'block';
    } else {
        alert('You must share your post before you can download.');
    }
}
Nate Barr
  • 4,640
  • 2
  • 25
  • 21
  • Thanks alot for your answer! it has helped alot. I need to ask another question now though. When the callback function executes the "download_box" instead of the text "Download Box (whatever that means) goes here" displaying can a direct link to a file automatically be opened? Thank you! –  Nov 21 '11 at 04:21
  • I'm not quite sure what you are asking, but here's a stab at the question: Just put an anchor tag in the download_box div, like `Download Now`. If you are asking about how to force a link to download, check out this [post](http://stackoverflow.com/questions/1465573/forcing-to-download-a-file-using-php). – Nate Barr Nov 21 '11 at 13:16
  • You nearly hit the nail on the head with that answer! With the 'Download Now' code inside the div it nearly works how i wanted it to but is there a way for the link "www.mydowmain.com/folder/file" to open without a user having to click "Download Now"? i have read the post you added about forcing links to download but it didnt seem to help. Thank you for all your help by the way! –  Nov 22 '11 at 11:44
  • Alright i just figured it out on my own i used the 'window.open' function instead of 'document.getElementById'. It opens the link i specify when the share button is pressed. The only thing is it opens it in a new tab rather than a window. I've tried some different attributes to get it to open in a new window but none seem to have any effect. It doesn't bother me to much at the moment so ill just figure it out when i can be bothered. Thank you for all your help and time! –  Nov 23 '11 at 06:53
  • Try this format: `link text` As MDN states, the [strWindowFeatures](https://developer.mozilla.org/en/DOM/window.open) string "must not contain any blank space, each feature name and value must be separated by a comma". BTW, The browser can decide how to implement the window.open function, so there is no guaranteed way to make it open a window instead of a tab. That said, _most_ browsers will not open a tab if attributes are set that would not make sense in the context of a tab. – Nate Barr Nov 23 '11 at 22:22