【问题标题】:Social Buttons do not share the current page info社交按钮不共享当前页面信息
【发布时间】:2015-07-17 00:48:13
【问题描述】:

我一直在尝试创建社交按钮,既可以自动捕获当前页面的 url,也可以捕获页面描述。

我已经经历了许多问题和答案(在 stackoverflow 中找到)并遵循了这些步骤,但我遇到了社交按钮行为的某种问题。

  1. facebook:它会弹出一个新窗口并提示我“输入要共享的 URL”。新页面的网址是:https://www.facebook.com/sharer/sharer.php?u
  2. twitter:简单地问我:“发生了什么事?”。弹窗网址为:https://twitter.com/intent/tweet?text=&url=about%3Ablank&original_referer=

  3. pinterest:在描述区域,它只是附加:@Url.Encode(PageTitle) popurl 是:https://www.pinterest.com/pin/create/button/?url=%40Url.Encode(Request.Url.ToString())&description=%40Url.Encode(PageTitle)

简而言之,似乎没有一个按钮生成任何页面 url,也没有描述和标题。

这是我的文件: index.html

    <a class="soc-facebook popup" href="javascript:window.location=%22http://www.facebook.com/sharer.php?u=%22+encodeURIComponent(document.location)+%22&#38;t=%22+encodeURIComponent(document.title)" title="Share on Facebook..." target="_blank"></a>
    <a class="soc-twitter popup" href="javascript:window.location=%22https://twitter.com/share?url=%22+encodeURIComponent(document.location)+%22&text=%22+encodeURIComponent(document.title)" target="_blank"></a>
    <a class="soc-pinterest popup" href="http://pinterest.com/pin/create/button/?url=@Url.Encode(Request.Url.ToString())&description=@Url.Encode(PageTitle)" target="_blank" title="Pin it"></a>
    <a class="soc-google popup" href="https://plusone.google.com/_/+1/confirm?hl=en&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank" title="Plus one this page on Google"></a>
    <a class="soc-linkedin soc-icon-last popup" href="http://www.linkedin.com/shareArticle?mini=true&url=<?php if(is_home()){echo home_url();}else{the_permalink();} ?>" target="_blank"></a>

pop.js

$(function() {
    // link selector and pop-up window size
    var Config = {
        Link: "a.popup",
        Width: 500,
        Height: 500
};

// add handler links
var slink = document.querySelectorAll(Config.Link);
for (var a = 0; a < slink.length; a++) {
    slink[a].onclick = PopupHandler;
}

// create popup
function PopupHandler(e) {

    e = (e ? e : window.event);
    var t = (e.target ? e.target : e.srcElement);

    // popup position
    var
        px = Math.floor(((screen.availWidth || 1024) - Config.Width) / 2),
        py = Math.floor(((screen.availHeight || 700) - Config.Height) / 2);

    // open popup
    var popup = window.open(t.href, "popup", 
        "width="+Config.Width+",height="+Config.Height+
        ",left="+px+",top="+py+
        ",location=0,menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1");
    if (popup) {
        popup.focus();
        if (e.preventDefault) e.preventDefault();
        e.returnValue = false;
    }

    return !!popup;
    }

}());

我可能哪里出错了?

谢谢!

【问题讨论】:

  • 顺便说一句,这些实际上是 3 个独立的问题,因为这与按钮和 javascript 无关。它与共享 API 有关。
  • 如果您已经为最后两个链接输出了带有服务器端代码的当前 URL – 那么为什么不对前三个链接做同样的事情呢?

标签: javascript jquery facebook twitter pinterest


【解决方案1】:
【解决方案2】:

这里的诀窍是向正在共享的页面添加 Open Graph 元标记。 Facebook 使用这些元标记来捕获页面元数据。如果您没有在页面上包含元标记,那么您至少可以为 Facebook 共享者明确输入参数。

有关如何包含这些标签的概要,请参阅此页面:

http://ogp.me/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 2016-01-09
    • 1970-01-01
    • 2011-10-30
    • 2017-08-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多