Facebook共享URL有哈希

时间:2015-04-13 08:24:02

标签: facebook url share

我的单页网站有一些产品,点击时产品详细信息显示为简单的弹出窗口。每个产品都有Facebook分享。但是当我在Facebook上分享网址时,在共享网址中说www.example.com#product1 #product1被剥离。

FB.ui({
  method: 'share',
  href: 'http://example.com/#product1',
}, function(response){});

当我分享时,它仅为http://example.com/,而非http://example.com/#product1。我希望像http://example.com/#product1一样分享完整的网址。它以某种方式被剥夺了。

如何避免这种情况?

5 个答案:

答案 0 :(得分:5)

与CBroe一样,Facebook会对网址进行索引,#不会被视为网址的一部分。

解决方案是使用“hashbang”#!表示法。 Facebook遵循Google Ajax Specification允许索引,在这种情况下,Ajax网站。

效果是http://www.example.com/#!/product1将被重写,而对服务器的查询将变为http://www.example.com/?_escaped_fragment_=/product1。反过来,您可以在服务器上捕获该内容并使用专用于该产品的页面进行回复。

您可以在此处阅读更详细的答案:https://stackoverflow.com/a/15024853/561485

最重要的是,您的网站应该能够为每个产品提供专用页面;如果您只有索引页,则使用#表示法将始终共享相同的URL。

答案 1 :(得分:1)

现在Facebook和Twitter不允许共享包含#标记的网址。不过,您可以使用%23代替#

来共享网址
<a class="twitter-share" href="https://twitter.com/intent/tweet?url=http://www.goparties.com/%23/party/{{id}}" target="_blank">

答案 2 :(得分:1)

您还可以使用encodeURIComponent

转义网址
FB.ui({
  method: 'share',
  href: encodeURIComponent('http://example.com/#product1'),
}, function(response){});

答案 3 :(得分:0)

取决于需求及其实现方式,可以使用goo.gl API生成唯一的可共享链接。

实现它的两种方法如下: 1.手动,只需访问goo.gl并发布包括#hash_tag在内的完整链接(可通过Facebook分享) 2.使用API​​进行自动共享任务...例如应用程序等,使用goo.gl url short API。

答案 4 :(得分:0)

共享对话框现在支持主题标签参数

  FB.ui({
    method: 'share',
    href: 'https://developers.facebook.com/docs/',
    hashtag: '#facebook'
  }, function(response){});

请参阅fb文档: https://developers.facebook.com/docs/sharing/reference/share-dialog/