在帖子中使用 HTML Twitter 分享按钮时,需要在 URL 中的博主标题中编码垂直条/管道



我正在尝试在网址中对Blogger标题中的垂直条进行编码,因为当我在帖子上按下html推文按钮时,Twitter的弹出窗口不会显示任何要推文的内容。但是,当我将垂直条编码为 %7C 时,一切正常。

例如,MSNBC使用垂直条在Youtube上拆分他们的标题,我会自动将他们的视频嵌入到我的一个博客上。看这里:

唐纳德·特朗普总统周五的推文:"伊朗在玩火" | 晨乔 |MSNBC

https://us-gov.blogspot.com/2017/02/president-donald-trumps-friday-tweet.html

但是,如果有人试图在推特上发布帖子,他们会得到一个空白屏幕,网址为 https://twitter.com/share?url=https://us-gov.blogspot.com/2017/02/president-donald-trumps-friday-tweet.html&text=President%20Donald%20Trump%27s%20Friday%20Tweet:%20%27Iran%20Is%20Playing%20With%20Fire%27%20|%20Morning%20Joe%20|%20MSNBC

但是如果我将竖线编码为 %7C,Twitter 窗口工作正常。

https://twitter.com/share?url=https://us-gov.blogspot.com/2017/02/president-donald-trumps-friday-tweet.html&text=President%20Donald%20Trump%27s%20Friday%20Tweet:%20%27Iran%20Is%20Playing%20With%20Fire%27%20%7C%20Morning%20Joe%20%7C%20MSNBC

我只是想知道是否有一种简单的方法可以防止在我的博客模板的 html 代码中发生这种情况。或者,如果有一个简单的脚本可供使用。

谢谢。

而不是使用当前共享 URL,其形式为 -

<a expr:href='&quot;https://twitter.com/share?url=&quot; + data:post.url + &quot;&amp;text=&quot; + data:post.title' aria-label='' class='resp-sharing-button__link' rel='nofollow' target='_blank'>Twitter</a>

使用博主提供的原生共享网址生成器 -

<a expr:href='&quot;https://www.blogger.com/share-post.g?blogID=&quot; + data:blog.blogId + &quot;&amp;postID=&quot; + data:post.id + &quot;&amp;target=twitter&quot;' aria-label='' class='resp-sharing-button__link' rel='nofollow' target='_blank'>Twitter</a>

这将生成表单的 URL -

https://www.blogger.com/share-post.g?blogID=BLOGID&postID=POSTID&target=twitter

然后,这将自动重定向到Twitter共享窗口,并自动填充帖子的标题和URL。帖子的标题将被转义。这个共享URL生成器也可用于为其他社交网络生成共享URL(又名facebookpinterestemailgoogleplus通过替换target参数)

这样做的缺点是您无法添加要关注的用户或添加主题标签,就像您在构建Twitter共享URL时通常能够做到的那样。

最新更新