samedi 10 janvier 2015

Adding the Fb SDK to invoke Share Dialog issues when JS needs to be inserted into PHP


Vote count:

0




I have had a look around and I feel my issue is not covered.


I have been following a tutorial here.


I have enabled sharing on my web app using the the JS SDK along with the social sharing button. So I have something that works.


However - I am unable to get the Share Dialog to work. And I am keen to understand whu, and fill a few gaps in my understanding of PHP and JS along the way.


Part of the problem is I am unsure where to put the the JS that triggers the pop up.


The element that contains the share button is a method in webapp that's contained in PHP tags.


this file is called info-box.php



<php
// some code

$shareIcons .= '<img src = "share_button.png" id = "share_button">';

// some code
?>


The variable $shareicons is called and helps render the HTML.


The ID share_button points to this JS - which I currently have in the head.php file along with the rest of the code



<script type="text/javascript">
$(document).ready(function(){
$('#share_button').click(function(e){
e.preventDefault();
FB.ui(
{
method: 'feed',
name: 'StakeMyRep',
link: 'http://ift.tt/1lvGCU3',
picture: 'http://ift.tt/1w84NvU',
caption: 'This is the content of the "caption" field.',
description: 'This is the content of the "description" field, below the caption.',
message: ''
});
});
});
</script>


Q1 - does this code need to sit before or after the ID share_button?


Q2 - Because this code is run in PHP tags, can I place this script in a div in the file info-php or should I place it elsewhere? Or, should I try escape the JS and place it in the PHP tags file?


Thanks in advance!



asked 1 min ago







Adding the Fb SDK to invoke Share Dialog issues when JS needs to be inserted into PHP

Aucun commentaire:

Enregistrer un commentaire