HTML:
<a href="#" onClick="return fbs_click(600, 400,'MyURL?image_name=<?php echo $row['image_name'] ?>&caption=<?php echo $row['caption']?>')" target="_blank" title="I just visited the Baidu Moustache Studio!"><img src="/assets/fbshare.png" alt="facebook share" height="22"></a>
Javascript:
function fbs_click(width, height,url) {
u=location.href;
t= "Title";
/*Url to update metadata */
var updatemetadate = "https://graph.facebook.com/?id="+encodeURIComponent(url)+"&scrape=true"
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
console.log("meta data updated!");
var leftPosition, topPosition;
//Allow for borders.
leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
//Allow for title and status bars.
topPosition = (window.screen.height / 2) - ((height / 2) + 50);
var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(url)+'&t='+encodeURIComponent(t),'sharer', windowFeatures);
return false;
}
}
xmlhttp.open("GET",updatemetadate,true);
xmlhttp.send();
}
现在,当我单击共享时,图像在前几次尝试中不会出现,但稍后会出现。似乎元标记更新较晚。
任何指针?
谢谢,
ps 也尝试了新的 Facebook(https://developers.facebook.com/docs/sharing/web)重定向方法。结果是一样的。