I want to open share pop up window of facebook when user clicks on a particular link (Not the share button). I want to do this in php and want to share an image.
Note: I want to provide the source of the image which comes dynamically.
Can any one help me please?
Please ask for more information if you want.
Thank you.
Update:
Below is my code:
The main page where the link is:
<li id="FB_post" style="display:none;"><a id="post_image_href" href="https://www.facebook.com/sharer/sharer.php" target="_blank">Facebook</a></li>
In the js (Click event)
$("#post_image_href").click(function(e) {
if($('.prodct_personalize_but a').html() != 'Cancel' && $('#zoom1').length>0 ){
$(this).attr('href','https://www.facebook.com/sharer/sharer.php?u='+$('#zoom1').attr('href'));
}
else if ($(".image-main-container").css('display') != 'none')
{
if ($('.product_box23').css('display') != 'none')
{
e.preventDefault();
setProperDynamicTextPosition();
var data = $('#personalise_form').serialize();
$('#loader_img').show();
$.post(ajaxurl, data + '&action=save_personalise_image', function(response) {
if (response != '' && response != undefined) {
var Aryresponse = response.split('###');
$("#post_image_href").attr('href','https://www.facebook.com/sharer/sharer.php?u=' + Aryresponse[0]);
document.location.href = $("#post_image_href").attr('href');
$('#loader_img').hide();
}
});
}
}
});
Link which is created when I click on the Facebook link and go to facebook page:
In share dilog box: the current url of the browser and in the address bar: the updated link. For Ex. https://www.facebook.com/sharer/sharer.php?u=https://www.picpixa.com/wp-content/plugins/create-own-object/test-img/final_ProductImage_1405751994-2197.png
Please let me know if you want more information.
Update In JS Function:
I have made change in my js (click event function):
Below is the updated function:
$("#post_image_href").click(function(e) {
var url='';
if($('.prodct_personalize_but a').html() != 'Cancel' && $('#zoom1').length>0 ){
//$(this).attr('href','https://www.facebook.com/sharer/sharer.php?u='+$('#zoom1').attr('href'));
url = 'https://www.facebook.com/sharer/sharer.php?u='+$('#zoom1').attr('href');
console.log("If: "+ $('#zoom1').attr('href'));
console.log("URL: "+ url);
}
else if ($(".image-main-container").css('display') != 'none')
{
if ($('.product_box23').css('display') != 'none')
{
e.preventDefault();
setProperDynamicTextPosition();
var data = $('#personalise_form').serialize();
$('#loader_img').show();
$.post(ajaxurl, data + '&action=save_personalise_image', function(response) {
if (response != '' && response != undefined) {
var Aryresponse = response.split('###');
//$("#post_image_href").attr('href','https://www.facebook.com/sharer/sharer.php?u=' + Aryresponse[0]);
url = 'https://www.facebook.com/sharer/sharer.php?u=' + Aryresponse[0];
console.log("Else: "+ Aryresponse[0]);
console.log("URL: "+ url);
window.open(url, "popupWindow", "width=450,height=400,scrollbars=no"); //If I don't use this the pop up don't open.
//In fact this is og no use as this is not opening but still I have to put this here to run below winodw.open.
$('#loader_img').hide();
}
});
}
}
console.log("The URL is: "+url);
window.open(url, "popupWindow", "width=450,height=400,scrollbars=no");
});
Another Update: Imp. Info:
I thought that this might me the issue of the Meta Tags. And it is. I am giving all the required meta tags in the main page but when I did the debug of the url I am passing it is giving me the below result.
Can anyone find me a solution?