javascript 可以在 Facebook 共享中使用哈希标签吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9610156/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using hash tags with Facebook share possible?
提问by Staffan Estberg
I'm developing an ajax based web site and I want to include a FB share function on the loaded content. The links use a hash tag and I can't manage to get the full links to show up when using the share function, I only get the domain url. Are hash tags not allowed or is there a special method for sharing such links?
我正在开发一个基于 ajax 的网站,我想在加载的内容上包含一个 FB 共享功能。链接使用哈希标签,我无法在使用共享功能时显示完整链接,我只能获取域 url。是否不允许使用哈希标签,或者是否有特殊方法可以共享此类链接?
回答by Ryan
Use URL Encoding for the #
character. Just replace the following:
对#
字符使用 URL 编码。只需替换以下内容:
http://www.example.com/#/path/to/whatever/
with:
和:
http://www.example.com/%23/path/to/whatever/
This will allow you to pass the #
to share on Facebook, Twitter, etc without getting stripped.
这将允许您通过#
在 Facebook、Twitter 等上分享而不会被剥夺。
回答by josh3736
Take a look at Google's answer to the AJAX content problem, the hashbang.
看看谷歌对 AJAX 内容问题的回答hashbang。
Basically, on your AJAX page, set the hash to !/path/to/whatever/
– in other words,
基本上,在您的 AJAX 页面上,将哈希设置为!/path/to/whatever/
– 换句话说,
http://www.example.com/#!/path/to/whatever/
Keep in mind your server must actually serve content similar to what you'd see in the AJAX application at http://www.example.com/path/to/whatever/
.
请记住,您的服务器实际上必须提供类似于您在http://www.example.com/path/to/whatever/
.
I'm not sure if Facebook respects the hashbang, but it does at least solve Googlebot problems for you. Edit:It looks like Facebook doesn't support the hashbang. You'll probably have to set up a redirector page.
我不确定 Facebook 是否尊重 hashbang,但它至少确实为您解决了 Googlebot 问题。 编辑:看起来 Facebook不支持 hashbang。您可能必须设置重定向器页面。