Facebook Sharer弹出窗口 [英] facebook Sharer popup window

查看:137
本文介绍了Facebook Sharer弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FB sharer弹出窗口显示页面的数据,而不是PHP插入的元数据。

  < a href =http://www.facebook.com/sharer/sharer.php?s=100&p%5Btitle%5D=Google&p%5Burl%5D=http%3A%2F%2Fwww.google。 com& p%5Bsummary%5D = Google搜索引擎& p%5Bimages%5D%5B0%5D = https://www.google.com/images/srpr/logo3w.png 
onClick =return fbs_click( 626,305)target =_ blanktitle =Share> FACEBOOK< / a>

似乎是由javascript引起的

 < script type =text / javascript> 
函数fbs_click(width,height){
var leftPosition,topPosition;
leftPosition =(window.screen.width / 2) - ((width / 2)+ 10);
topPosition =(window.screen.height / 2) - ((height / 2)+ 50);
var windowFeatures =status = no,height =+ height +,width =+ width +,resizable = no,left =+ leftPosition +,top =+ topPosition +,screenX = + leftPosition +,screenY =+ topPosition +,toolbar = no,menubar = no,scrollbars = no,location = no,directories = no;
u = location.href;
t = document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'& t ='+ encodeURIComponent(t),'sharer',windowFeatures) ;
返回false;
}
< / script>

如何在弹出窗口中显示正确的数据?

解决方案

如果要添加自定义元数据,请使用以下代码:

 < a id =fb-sharestyle ='text-decoration:none;'type =icon_linkonClick =window.open('http://www.facebook.com/sharer.php?s = 100安培; p [标题] = YOUR_TITLE&安培; p [摘要] = YOUR_DESCRIPTION&安培; p [URL] = YOUR_URL&安培; p [图像] [0] = YOUR_IMAGE ' '共享者',' 工具栏= 0,状态= 0,宽度= 580,高度= 325' ); href =javascript:void(0)> Share< / a> 

更新:





Javascript:

 函数fbShare(url,title,descr,image ,winWidth,winHeight){
var winTop =(screen.height / 2) - (winHeight / 2);
var winLeft =(screen.width / 2) - (winWidth / 2);
window.open('http://www.facebook.com/sharer.php?s=100&p [title] ='+ title +'& p [summary] ='+ descr +'& ; p [url] ='+ url +'& p [images] [0] ='+ image,'sharer','top ='+ winTop +',left ='+ winLeft +',toolbar =状态= 0,宽度= '+ winWidth +',高度='+ winHeight);
}

HTML:

 < a href =javascript:fbShare('http://jsfiddle.net/stichoza/EYxTJ/','Fb Share','Facebook share popup','http://goo.gl/dS52U',520,350)> Share< / a> 


The FB sharer popup window displays the data of the page, not the metadata I have inserted in the php link.

<a href="http://www.facebook.com/sharer/sharer.php?s=100&p%5Btitle%5D=Google&p%5Burl%5D=http%3A%2F%2Fwww.google.com&p%5Bsummary%5D=Google search engine&p%5Bimages%5D%5B0%5D=https://www.google.com/images/srpr/logo3w.png
"onClick="return fbs_click(626, 305)" target="_blank" title="Share">FACEBOOK</a>

It seems the to be caused by the javascript

<script type="text/javascript">
function fbs_click(width, height) {
var leftPosition, topPosition;
leftPosition = (window.screen.width / 2) - ((width / 2) + 10);
topPosition = (window.screen.height / 2) - ((height / 2) + 50);
var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=no,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no";
u=location.href;
t=document.title;
window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer', windowFeatures);
return false;
}
</script>

How can I display the correct data in the popup window?

解决方案

If you want to add custom metadata, use following code:

<a id="fb-share" style='text-decoration:none;' type="icon_link" onClick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=YOUR_TITLE&p[summary]=YOUR_DESCRIPTION&p[url]=YOUR_URL&p[images][0]=YOUR_IMAGE','sharer','toolbar=0,status=0,width=580,height=325');" href="javascript: void(0)">Share</a>

UPDATE:

I wrote a little JS code for Facebook Share.

Javascript:

function fbShare(url, title, descr, image, winWidth, winHeight) {
        var winTop = (screen.height / 2) - (winHeight / 2);
        var winLeft = (screen.width / 2) - (winWidth / 2);
        window.open('http://www.facebook.com/sharer.php?s=100&p[title]=' + title + '&p[summary]=' + descr + '&p[url]=' + url + '&p[images][0]=' + image, 'sharer', 'top=' + winTop + ',left=' + winLeft + ',toolbar=0,status=0,width='+winWidth+',height='+winHeight);
    }

HTML:

<a href="javascript:fbShare('http://jsfiddle.net/stichoza/EYxTJ/', 'Fb Share', 'Facebook share popup', 'http://goo.gl/dS52U', 520, 350)">Share</a>

这篇关于Facebook Sharer弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆