简体   繁体   English

动态Twitter分享按钮

[英]Dynamic Twitter Share button

Here's the code that extracts the Title and the URL of the current page and shares it on twitter. 这是提取当前页面的标题和URL并在Twitter上共享的代码。

I need help adding @TwitterHandle after the title text and couldn't get it to work so it reads while sharing: "Title URL @TwitterHandle" 我需要在标题文本后添加@TwitterHandle的帮助,但无法使其正常工作,因此在共享时会读取:“标题URL @TwitterHandle”

Would appreciate your quick input. 感谢您的快速输入。 Thanks. 谢谢。

<script>
function tweetCurrentPage()
{ window.open("https://twitter.com/share?url="+escape(window.location.href)+"&text="+document.title, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');return false; }
</script>

<a class="tweet" href="javascript:tweetCurrentPage()" target="_blank" alt="Tweet this page"><span>Tweet</span></a>

Twitter handle needs to be passed as the part of the text URL parameter. Twitter句柄需要作为text URL参数的一部分传递。 Please refer the below code snippet. 请参考以下代码片段。

<script>
var twitterHandle = 'sarbbottam';

function tweetCurrentPage() {
    window.open('https://twitter.com/share?url='+escape(window.location.href)+'&text='+document.title + ' via @' + twitterHandle, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=300,width=600');
    return false; 
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM