Html 如何制作一个只是链接而不是 iFrame 的 Facebook“赞”按钮?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2954888/
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
How to make a Facebook "Like" button that is just a link, not an iFrame?
提问by danwood
I would like to put a "Like" button into an email message that it going out to our e-newsletter subscribers. The usual way of embedding a Like button, which uses, an iframe technique, is not going to work.
我想在发送给我们的电子通讯订阅者的电子邮件中添加一个“喜欢”按钮。使用 iframe 技术嵌入 Like 按钮的常用方法是行不通的。
What I would like to do is to have a static hyperlink, where clicking on the button image will just go to a particular URL that is our corresponding Facebook page, and do the action of becoming a fan.
我想要做的是有一个静态超链接,点击按钮图像将转到我们相应的 Facebook 页面的特定 URL,并执行成为粉丝的操作。
Can anybody figured out an official or unofficial kind of URL that one could link to that takes you to the page on Facebook and performs the appropriate action?
任何人都可以找到一种官方或非官方的 URL,可以链接到该 URL 将您带到 Facebook 上的页面并执行适当的操作?
回答by roborourke
It would be a horribly insecure system if a link could force the action to happen. People would be 'liking' things all the shop that they didn't want to. Imagine how easy it would be for companies to send out a shortened URL on twitter and get hundreds of illicit 'likes'.
如果链接可以强制执行操作,那将是一个非常不安全的系统。人们会“喜欢”所有他们不想喜欢的东西。想象一下,公司在 twitter 上发送一个缩短的 URL 并获得数百个非法“喜欢”是多么容易。
It's better to let people do that explicitly themselves so from an email the best you can do is to link people to the facebook page and hope they'll click like. If it's a good/useful page then chances are they will.
最好让人们自己明确地这样做,因此从电子邮件中,您能做的最好的事情就是将人们链接到 facebook 页面,并希望他们会点赞。如果这是一个好的/有用的页面,那么他们很有可能会这样做。
One approach is to have the email aimed at getting people to a landing page on your own site. You can then have a like button on that and using the Open Graph Protocolmeta tags have that 'like' applied to the home page or whole site.
一种方法是让电子邮件旨在让人们访问您自己网站上的登录页面。然后,您可以在其上添加一个喜欢按钮,并使用开放图谱协议元标记将该“喜欢”应用于主页或整个站点。
If you want your like button on the landing page to be a general one for the entire site then use the canonical og:url meta tag eg:
如果您希望着陆页上的“赞”按钮成为整个网站的通用按钮,请使用规范的 og:url 元标记,例如:
<meta name="og:url" content="http://yoursite.com/" />
回答by Bharata
It was never possible to like some site with Facebook "Like" plugin from email for security reasons. Only if some server administrator does not cut the JS or iframes, but it is not normal – most email servers cut it.
出于安全原因,永远不可能从电子邮件中喜欢某些带有 Facebook“Like”插件的网站。只有当某些服务器管理员不剪掉 JS 或 iframes,但这是不正常的——大多数电子邮件服务器剪掉了它。
This answer(from Yevgeniy Afanasyev) is absolutely wrong! It was never worked! The code in this answer gives you only the possibility to go to Facebook page and then you have there the possibility to like this site. All this code from this answer doesn't more than give you the link like this:
这个答案(来自 Yevgeniy Afanasyev)是绝对错误的!它从来没有工作过!这个答案中的代码只让你有可能去 Facebook 页面,然后你就有可能喜欢这个网站。这个答案中的所有这些代码只不过是给你这样的链接:
https://www.facebook.com/plugins/like.php?href=https://stackoverflow.com
In the part href=https://stackoverflow.com
from this link you could put any other site adress. If you have in this adress some &
character then you have to replace it with &
.
在href=https://stackoverflow.com
此链接的部分中,您可以放置任何其他站点地址。如果您在此地址中有某个&
字符,则必须将其替换为&
.
And do not think that if this answer was many times upvoted then it is correct or was worked. I think this users which upvoted this unswer do not understand what they have done. They have seen some code and upvoted it without thinking or without understanding.
并且不要认为如果这个答案被多次投票,那么它是正确的或有效的。我认为这个支持这个 unswer 的用户不明白他们做了什么。他们看到了一些代码,并在没有思考或理解的情况下就对它进行了投票。
Why is this not possible
为什么这是不可能的
Just imagine you get an email and some link button in it with text "Very funny videos". And then if you click on it then you would like some site which you do not like or do not know. And because of this for security reasons it was never possible.
想象一下,您收到一封电子邮件,其中包含一些带有“非常有趣的视频”字样的链接按钮。然后如果你点击它,那么你会喜欢一些你不喜欢或不知道的网站。由于安全原因,这是不可能的。
You have always to confirm all your actions if you use some links.
如果您使用某些链接,您必须始终确认您的所有操作。
Possible workaround
可能的解决方法
Instead of this link you could write some nice landing page for your site and in email you could write this link in email button with adress to this page. And in this page you can use normal Facebook "Like" plugin.
您可以为您的网站编写一些不错的登录页面,而不是此链接,而在电子邮件中,您可以在电子邮件按钮中编写此链接,并附上该页面的地址。在此页面中,您可以使用普通的 Facebook“Like”插件。
回答by Yevgeniy Afanasyev
It was never possible to like some site with Facebook "Like" plugin from email for security reasons.
出于安全原因,永远不可能从电子邮件中喜欢某些带有 Facebook“Like”插件的网站。
But sometimes it is difficult to explain it to your boss, who wants something similar that others emails have. If this was your case, you could offer my answer to your management.
但有时很难向你的老板解释,他想要一些与其他电子邮件类似的东西。如果这是你的情况,你可以向你的管理层提供我的答案。
The following code doesn't make you a fan of the page but rather likes the site's home page, and it gives you a Like button and "X people like this. Be the first of your friends."
以下代码不会让您成为该页面的粉丝,而是喜欢该站点的主页,它为您提供一个“赞”按钮和“X 个人喜欢这个。成为您的第一个朋友”。
If this is what you want, please see the code:
如果这是你想要的,请看代码:
replace http://eyeclarity.com.au- to your site and if you do not like my like button, replace http://www.4wdaction.com.au/_phpBB/download/file.php?id=68849with your one
将http://eyeclarity.com.au-替换为您的站点,如果您不喜欢我的“赞”按钮,请将http://www.4wdaction.com.au/_phpBB/download/file.php?id=68849替换 为您的一
<a title="Like this on Facebook"
href="http://www.facebook.com/plugins/like.php?href=http://eyeclarity.com.au&
layout=standard&
show_faces=false&
width=450&
action=like&
colorscheme=light&"
>
<img title="Facebook Like Button"
src="https://upload.wikimedia.org/wikipedia/commons/1/13/Facebook_like_thumb.png"
alt=""
height="50"
width="50"
/>
</a>
aforementioned code will redirect you to a link, that looks like this
上述代码会将您重定向到一个链接,如下所示
https://www.facebook.com/plugins/like.php?href=http://eyeclarity.com.au&%20%20%20layout=standard&%20%20%20show_faces=false&%20%20%20width=450&%20%20%20action=like&%20%20%20colorscheme=light&
Now, you can try clicking it and see some animation that Facebook is offering.
现在,您可以尝试单击它并查看 Facebook 提供的一些动画。
回答by ik1ne
In addition to another answers that says it's impossible, I'll show a brief explanation why it should not be supported by the Facebook(or any other sites that requires login).
除了另一个说不可能的答案之外,我将简要说明为什么 Facebook(或任何其他需要登录的网站)不支持它。
Let's suppose someone had a post, and Facebook gave the href that automatically likes the post to the owner. (let's just say fb.com/like/post_id
for simplicity's sake)
假设某人有一个帖子,Facebook 将自动喜欢该帖子的 href 提供给所有者。(fb.com/like/post_id
为了简单起见,我们只是说)
What happens if he rolls out email newsletters that includes some tag like this?
如果他推出包含此类标签的电子邮件通讯,会发生什么?
<img src="fb.com/like/post_id" />
It's not definitely a img src, but web browsers will try to connect to fb.com/like/post_id
anyway, and...boom. By reading this email you automatically liked that post regardless of your intention.
它绝对不是一个 img src,但是 Web 浏览器fb.com/like/post_id
无论如何都会尝试连接,并且...繁荣。通过阅读这封电子邮件,无论您的意图如何,您都会自动喜欢该帖子。
This is why it shouldn't be possible to roll out email that includes Like link.
这就是为什么不应该推出包含 Like 链接的电子邮件的原因。