-1

我正在尝试为我的网站创建自定义社交共享按钮,但我遇到了当前页面标题和 url 没有被正确拉出以与社交网络共享的问题。

我的代码示例如下所示:

<a class="share-btn twitter-btn twitter-sharer-button" id="ref_tw" href="https://twitter.com/intent/tweet?title=<?php echo $title; ?>&amp;url=<?php echo urlencode($share_url);?>&amp;via=Udamonia"  onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=no,scrollbars=no,height=400,width=600');return false;"></a>

非常感谢任何帮助或正确方向的观点。

谢谢!

4

1 回答 1

0

在 onclick 事件中使用 Javascript 来获取document.titledocument.location.href然后将其附加到共享 URL 并随后将新 URL 设置为。

所以你的 onclick 属性看起来像:

onlick="javascript:window.open('http://twitter.com/intent?title='+encodeURIComponent(document.title)+';url='+encodeURIComponent(document.location.href);"
于 2014-03-19T16:22:41.720 回答