与LinkedIn共享API共享时出现Javascript错误
我有以下代码:与LinkedIn共享API共享时出现Javascript错误,javascript,Javascript,我有以下代码: $(".btn_li").click(function() { window.open("http://www.linkedin.com/shareArticle?mini=true&url='+document.URL+'&title=Webpage Title;summary=Webpage Summary", "LinkedIn", "width=660,height=400,scrollbars=no;resizable=no")
$(".btn_li").click(function() {
window.open("http://www.linkedin.com/shareArticle?mini=true&url='+document.URL+'&title=Webpage Title;summary=Webpage Summary", "LinkedIn", "width=660,height=400,scrollbars=no;resizable=no");
try {
_gaq.push(['_trackEvent', 'Social', 'LinkedIn', "Page URL"]);
} catch(err){}
return false;
});
请从以下地址拨打:
<div class="btn_li"></div>
单击此按钮时,我收到的LinkedIn错误是:“出现了一个意外问题,使我们无法完成您的请求。”这告诉我参数传递不正确
有什么建议吗
注意:这是我原来问题的一个新问题: 您需要对每个参数进行编码,请参见
示例:例如,您需要对其进行正确编码
function fixedEncodeURIComponent(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function(c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
$(".btn_li").click(function() {
var url = fixedEncodeURIComponent('http://yourURL.com');
window.open("https://www.linkedin.com/sharing/share-offsite/?url=" + url);
});
Microsoft开发人员网络文档中说,永远不要直接使用encodeURIComponent(),而要使用此函数。看一看:
我还修复了您的url,/share offsite/
是新标准,shareArticle?
是已弃用的旧标准。来源:
最后,标题
、摘要
和源
参数也都已被弃用。您只能使用HTML源代码的
块中的og:
标记来填充这些字段。例如,这看起来像
谢谢你的回复,贾斯汀,恐怕没有变化。事实上,我是从引语开始的,我想试试别的。
function fixedEncodeURIComponent(str) { return encodeURIComponent(str).replace(/[!'()*]/g, function(c) { return '%' + c.charCodeAt(0).toString(16); }); } $(".btn_li").click(function() { var url = fixedEncodeURIComponent('http://yourURL.com'); window.open("https://www.linkedin.com/sharing/share-offsite/?url=" + url); });