为什么 Facebook 使用提交按钮而不仅仅是点赞按钮的链接?

发布于 2024-10-17 22:50:17 字数 5442 浏览 3 评论 0原文

在此处输入图像描述

我一直想知道为什么 facebook 使用类似“从按钮提交”而不只是简单的链接来执行操作,以下是类似按钮的代码。

<form rel="async" class="live_184361748268334 commentable_item autoexpand_mode" method="post" action="/ajax/ufi/modify.php" data-live="{&quot;seq&quot;:0}" onsubmit="return Event.__inlineSubmit(this,event)">
  <input name="charset_test" value="€,´,€,´,水,Д,Є" type="hidden">
  <input autocomplete="off" name="post_form_id" value="1ef694751d74ce24382cfa6181f1adfe" type="hidden">
  <input name="fb_dtsg" value="_19R5" autocomplete="off" type="hidden">
  <input autocomplete="off" name="feedback_params" value="{&quot;actor&quot;:&quot;514782389&quot;,&quot;target_fbid&quot;:&quot;184361748268334&quot;,&quot;target_profile_id&quot;:&quot;514782389&quot;,&quot;type_id&quot;:&quot;17&quot;,&quot;source&quot;:&quot;1&quot;,&quot;assoc_obj_id&quot;:&quot;&quot;,&quot;source_app_id&quot;:&quot;2309869772&quot;,&quot;extra_story_params&quot;:[],&quot;content_timestamp&quot;:&quot;1298066944&quot;,&quot;check_hash&quot;:&quot;e76c88ca6e20b4a0&quot;}" type="hidden">
  <div class="UIImageBlock clearfix"><i class="UIImageBlock_Image UIImageBlock_ICON_Image img sp_4b2fk0 sx_b64365"></i>
    <div class="UIImageBlock_Content UIImageBlock_ICON_Content"><span class="uiStreamSource"><a href="/aleem.sheikh/posts/184361748268334"><abbr title="Saturday, February 19, 2011 at 3:09am" data-date="Fri, 18 Feb 2011 14:09:04 -0800" class="timestamp">4 hours ago</abbr></a></span><span class="UIActionLinks UIActionLinks_bottom" data-ft="{&quot;type&quot;:&quot;action&quot;}"> ·
        <button class="like_link stat_elem as_link" title="Like this item" type="submit" name="like" onclick="fc_click(this, false); return true;"><span class="default_message">Like</span><span class="saving_message">Unlike</span></button>
        ·
        <label class="uiLinkButton comment_link" onclick="return fc_click(this);" title="Leave a comment">
          <input value="Comment" type="button">
        </label>
        · <a title="Send this to friends or post it on your profile." href="/ajax/share_dialog.php?s=99&amp;appid=2309869772&amp;p%5B0%5D=514782389&amp;p%5B1%5D=184361748268334" rel="dialog">Share</a></span></div>
  </div>
  <ul class="uiList uiUfi focus_target fbUfi" data-ft="{&quot;type&quot;:&quot;ufi&quot;}">
    <li class="ufiNub uiListItem  uiListVerticalItemBorder"><i></i>
      <input autocomplete="off" name="xhp_ufi" value="1" type="hidden">
    </li>
    <li class="ufiItem uiUfiLike">
      <div class="UIImageBlock clearfix"><a class="UIImageBlock_Image UIImageBlock_ICON_Image" tabindex="-1">
          <label onclick="this.form.like.click();"><i class="img sp_8dfqpl sx_4ac53f" title="Like this item"></i></label>
        </a>
        <div class="UIImageBlock_Content UIImageBlock_ICON_Content"><a href="http://www.facebook.com/profile.php?id=100000407120411">Syed Murtaza Zaidi</a> likes this.</div>
      </div>
    </li>
    <li class="uiUfiComments uiListItem  uiListVerticalItemBorder hidden_elem">
      <ul class="commentList">
      </ul>
    </li>
    <li class="uiUfiAddComment clearfix ufiItem ufiItem uiListItem  uiListVerticalItemBorder uiUfiAddCommentCollapsed">
      <div><img class="uiProfilePhoto actorPic UIImageBlock_Image UIImageBlock_ICON_Image uiProfilePhotoMedium img" src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/41709_1014341698_4889488_q.jpg" alt="">
        <div class="commentArea UIImageBlock_Content UIImageBlock_ICON_Content">
          <div class="commentBox">
            <textarea class="DOMControl_placeholder uiTextareaNoResize uiTextareaAutogrow textBox textBoxContainer" title="Write a comment..." placeholder="Write a comment..." name="add_comment_text" onfocus="return wait_for_load(this, event, function() {if (!this._has_control) {new TextAreaControl(this).setAutogrow(true);this._has_control = true;}});">Write a comment...</textarea>
          </div>
          <label class="mts mts commentBtn stat_elem optimistic_submit uiButton uiButtonConfirm" for="u127419_35">
            <input value="Comment" name="comment" id="u127419_35" type="submit">
          </label>
        </div>
      </div>
    </li>
  </ul>
  <input value="{&quot;src&quot;:10,&quot;sty&quot;:263,&quot;actrs&quot;:&quot;514782389&quot;,&quot;object_id&quot;:184361748268334,&quot;pub_time&quot;:1298066944,&quot;fbid&quot;:&quot;184361748268334&quot;,&quot;qid&quot;:&quot;5575216616647978849&quot;,&quot;mf_objid&quot;:184361748268334,&quot;s_obj&quot;:5,&quot;s_edge&quot;:1,&quot;s_prnt&quot;:3,&quot;pos&quot;:9,&quot;filter&quot;:&quot;h&quot;}" name="link_data" type="hidden">
</form>

enter image description here

I keep wondering why did facebook use like submit from button and not just simple link to do the action with, following is there like button code.

<form rel="async" class="live_184361748268334 commentable_item autoexpand_mode" method="post" action="/ajax/ufi/modify.php" data-live="{"seq":0}" onsubmit="return Event.__inlineSubmit(this,event)">
  <input name="charset_test" value="€,´,€,´,水,Д,Є" type="hidden">
  <input autocomplete="off" name="post_form_id" value="1ef694751d74ce24382cfa6181f1adfe" type="hidden">
  <input name="fb_dtsg" value="_19R5" autocomplete="off" type="hidden">
  <input autocomplete="off" name="feedback_params" value="{"actor":"514782389","target_fbid":"184361748268334","target_profile_id":"514782389","type_id":"17","source":"1","assoc_obj_id":"","source_app_id":"2309869772","extra_story_params":[],"content_timestamp":"1298066944","check_hash":"e76c88ca6e20b4a0"}" type="hidden">
  <div class="UIImageBlock clearfix"><i class="UIImageBlock_Image UIImageBlock_ICON_Image img sp_4b2fk0 sx_b64365"></i>
    <div class="UIImageBlock_Content UIImageBlock_ICON_Content"><span class="uiStreamSource"><a href="/aleem.sheikh/posts/184361748268334"><abbr title="Saturday, February 19, 2011 at 3:09am" data-date="Fri, 18 Feb 2011 14:09:04 -0800" class="timestamp">4 hours ago</abbr></a></span><span class="UIActionLinks UIActionLinks_bottom" data-ft="{"type":"action"}"> ·
        <button class="like_link stat_elem as_link" title="Like this item" type="submit" name="like" onclick="fc_click(this, false); return true;"><span class="default_message">Like</span><span class="saving_message">Unlike</span></button>
        ·
        <label class="uiLinkButton comment_link" onclick="return fc_click(this);" title="Leave a comment">
          <input value="Comment" type="button">
        </label>
        · <a title="Send this to friends or post it on your profile." href="/ajax/share_dialog.php?s=99&appid=2309869772&p%5B0%5D=514782389&p%5B1%5D=184361748268334" rel="dialog">Share</a></span></div>
  </div>
  <ul class="uiList uiUfi focus_target fbUfi" data-ft="{"type":"ufi"}">
    <li class="ufiNub uiListItem  uiListVerticalItemBorder"><i></i>
      <input autocomplete="off" name="xhp_ufi" value="1" type="hidden">
    </li>
    <li class="ufiItem uiUfiLike">
      <div class="UIImageBlock clearfix"><a class="UIImageBlock_Image UIImageBlock_ICON_Image" tabindex="-1">
          <label onclick="this.form.like.click();"><i class="img sp_8dfqpl sx_4ac53f" title="Like this item"></i></label>
        </a>
        <div class="UIImageBlock_Content UIImageBlock_ICON_Content"><a href="http://www.facebook.com/profile.php?id=100000407120411">Syed Murtaza Zaidi</a> likes this.</div>
      </div>
    </li>
    <li class="uiUfiComments uiListItem  uiListVerticalItemBorder hidden_elem">
      <ul class="commentList">
      </ul>
    </li>
    <li class="uiUfiAddComment clearfix ufiItem ufiItem uiListItem  uiListVerticalItemBorder uiUfiAddCommentCollapsed">
      <div><img class="uiProfilePhoto actorPic UIImageBlock_Image UIImageBlock_ICON_Image uiProfilePhotoMedium img" src="http://profile.ak.fbcdn.net/hprofile-ak-snc4/41709_1014341698_4889488_q.jpg" alt="">
        <div class="commentArea UIImageBlock_Content UIImageBlock_ICON_Content">
          <div class="commentBox">
            <textarea class="DOMControl_placeholder uiTextareaNoResize uiTextareaAutogrow textBox textBoxContainer" title="Write a comment..." placeholder="Write a comment..." name="add_comment_text" onfocus="return wait_for_load(this, event, function() {if (!this._has_control) {new TextAreaControl(this).setAutogrow(true);this._has_control = true;}});">Write a comment...</textarea>
          </div>
          <label class="mts mts commentBtn stat_elem optimistic_submit uiButton uiButtonConfirm" for="u127419_35">
            <input value="Comment" name="comment" id="u127419_35" type="submit">
          </label>
        </div>
      </div>
    </li>
  </ul>
  <input value="{"src":10,"sty":263,"actrs":"514782389","object_id":184361748268334,"pub_time":1298066944,"fbid":"184361748268334","qid":"5575216616647978849","mf_objid":184361748268334,"s_obj":5,"s_edge":1,"s_prnt":3,"pos":9,"filter":"h"}" name="link_data" type="hidden">
</form>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

原野 2024-10-24 22:50:18

因为

  1. BUTTON type="submit"INPUT type="submit" 是提交表单的标准方式,
  2. 所以 Like-action 使用 POST 请求,因为应该使用 POST 请求当某些服务器端状态改变时。
  3. Like-action 包含多个具有长值的参数。某些浏览器对 URL 长度有限制,如果作为 GET 请求发送,like 操作的参数可能会超出该长度。
  4. 使用标准元素允许所有浏览器即使没有 JavaScript 也可以正确提交类似操作作为 POST 请求。使用链接将导致 GET 请求。

Because

  1. BUTTON type="submit" and INPUT type="submit" are the standard way to submit forms
  2. Like-action uses a POST-request because POST-requests should be used when some server-side state is altered.
  3. Like-action contains several parameters with long values. Some browsers have a limit to URL length and the parameters of the like-action might exceed that length if it was sent as a GET-request.
  4. Using standard elements allows all browsers to submit like-action correctly as a POST-request even without javascript. Using links would result in a GET-request.
落叶缤纷 2024-10-24 22:50:18

我从来没有注意到它是一个按钮而不是一个链接,很好的捕捉。

这可能是因为“赞”操作不是真正的链接。它不会带你去任何地方。因此,虽然他们将其设计为链接,但它实际上并不是链接。当然,他们可以使用链接,但我认为使用按钮更正确。单击按钮会执行操作,而不是通过链接转到新页面。这与你在 Facebook 上“喜欢”某件事时所发生的情况非常吻合。

I never noticed that it was a button and not a link, nice catch.

It's likely because the "Like" action isn't a true link. It doesn't take you anywhere. So while they styled it like a link, it isn't actually a link. They could have used a link, sure, but I think using the button is a bit more correct. Clicking a button performs an action, as opposed to a link which takes you to a new page. That matches well with what happens when you "like" something on facebook.

剪不断理还乱 2024-10-24 22:50:18

甚至移动版本似乎也使用链接。该按钮一定是他们认为需要支持更严格的浏览器设置时留下的。 ——阿列克西

Even the mobile version seems to use links. The button must be a remnant from the time they thought they needed to support more restrictive browser settings. – Aleksi

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文