简体   繁体   English

用于自定义URL(文本链接,图像或两者)的“自定义Pinterest”按钮

[英]Custom Pinterest button for custom URL (Text-Link, Image, or Both)

I tried to find the solution but can't. 我试图找到解决方案,但找不到。 I need a custom image for Pinterest (Pin It) button and pin some custom image by url but not a current page. 我需要一个用于Pinterest(自定义)按钮的自定义图像,并按url(而不是当前页面)固定一些自定义图像。

I created a custom link: 我创建了一个自定义链接:

<a href="http://pinterest.com/pin/create/button/?url=http://inspired-ui.com&media={ImageURL}&description=DescriptionText" class="pinitbutton">Pin It</a>

in style I set the background image but I see only default Pin It button and not my custom button 在样式上,我设置了背景图片,但仅看到默认的Pin It按钮,而没有看到自定义按钮

There are some solutions where you can set custom button image for Pin It button but I can't change the media={ImageURL} in those solutions. 在某些解决方案中,您可以为“ Pit It”按钮设置自定义按钮图像,但是在这些解决方案中,我无法更改media = {ImageURL}。

The popular solution is 流行的解决方案是

<a href='javascript:void((function()%7Bvar%20e=document.createElement(&apos;script&apos;);e.setAttribute(&apos;type&apos;,&apos;text/javascript&apos;);e.setAttribute(&apos;charset&apos;,&apos;UTF-8&apos;);e.setAttribute(&apos;src&apos;,&apos;http://assets.pinterest.com/js/pinmarklet.js?r=&apos;+Math.random()*99999999);document.body.appendChild(e)%7D)());'><img src='http://www.brandaiddesignco.com/blog/PinIt.png'/></a>

But it doesn't help me. 但这对我没有帮助。 Does any one know the solution? 有谁知道解决方案吗?

Indeed the popular solution by Jeremy Mansfield at www.brandaiddesignco.com has a great method to customize the Pinterest button any way you want ! 事实上,由杰里米·曼斯菲尔德在流行的解决方案www.brandaiddesignco.com有一个伟大的方法来定制的Pinterest的按钮, 任何你想要的

I've made three examples , in the form of jsFiddle's , so you can see how it's done using that method. 我已经以jsFiddle's的形式制作了三个示例 ,因此您可以看到使用该方法是如何完成的。

Reference: jsFiddle Text-Link method 参考: jsFiddle文本链接方法
Reference: jsFiddle Custom Logo method 参考: jsFiddle自定义徽标方法
Reference: jsFiddle Custom Logo and Image method 参考: jsFiddle自定义徽标和图像方法

For more Pinterest Info , see my other SO Answer . 有关更多的Pinterest信息 ,请参见我的其他SO Answer

Adding an encoded whitespace before the last fragment of the URL will prevent Pinterest's JS from "hijacking" the link: 在网址的最后一个片段之前添加编码的空格将防止Pinterest的JS“劫持”链接:

//pinterest.com/pin/create/%20button?url=

Update: 更新:

It seems that my previous solution doesn't work anymore. 看来我以前的解决方案不再起作用。 Here is another one: 这是另一个:

//pinterest.com/pin/create%2Fbutton/?url=

At the risk of over simplifying things, use your 'http://pinterest.com/pin/create/button/?url=' path that you've already got, set up your variables, and append them as you do, and just don't include any pinterest javascript. 冒着过于简化的风险,请使用已经拥有的'http://pinterest.com/pin/create/button/?url='路径,设置变量,然后按需添加它们,然后只是不包含任何pinterest javascript。 Without that js, it won't find the link and replace it out with their own pinterest button. 如果没有该js,它将无法找到链接,并用自己的pinterest按钮将其替换。 Just customize your link with an image inside it (or set a background image or whatever) and screw the pinterest js. 只需使用链接中的图片自定义链接(或设置背景图片或其他内容),然后拧紧pinterest js。 Set the target to open in a new window. 将目标设置为在新窗口中打开。

Custom Link/Button looks like this: 自定义链接/按钮如下所示:

<a href="http://stackoverflow.com/questions/11312923/custom-pinterest-button-for-custom-url-text-link-image-or-both" data-image="http%3A%2F%2Fcdn.sstatic.net%2Fstackexchange%2Fimg%2Flogos%2Fso%2Fso-logo.png" data-desc="Custom Pinterest button for custom URL (Text-Link, Image, or Both)" class="btnPinIt">
    Custom Pin it image or text here!
</a> 

Note: I don't think the data attributes need to be encoded (like I did for data-image) but it doesn't seem to hurt it. 注意:我认为不需要对数据属性进行编码(就像我对数据图像所做的那样),但这似乎并不会对它造成伤害。

JQuery: jQuery的:

$('.btnPinIt').click(function() {
    var url = $(this).attr('href');
    var media = $(this).attr('data-image');
    var desc = $(this).attr('data-desc');
    window.open("//www.pinterest.com/pin/create/button/"+
    "?url="+url+
    "&media="+media+
    "&description="+desc,"_blank");
    return false;
});

Here is what worked for me : 这是对我有用的东西:

<a href="//www.pinterest.com/pin/create/button/" data-pin-do="buttonPin" data-pin-custom="true"><img src="../img/custompinint.png" /></a>

The attribute data-pin-custom is what I picked up from Pinterest documentation . 我从Pinterest文档中获得了data-pin-custom属性。

Hope this helps. 希望这可以帮助。

After a bit of trial and error, below is what worked for me. 经过一番尝试和错误之后,以下是对我有用的方法。 This response is a combination of @rharvey's response thread and another stack overflow post. 此响应是@rharvey的响应线程和另一个堆栈溢出帖子的组合。 This solution opens up a pop up to share content via pinterest. 该解决方案打开了一个弹出窗口,可通过pinterest共享内容。

Note: In order to prevent 2 windows from popping up you need to set a target. 注意:为了防止2个窗口弹出,您需要设置一个目标。 Below is the full solution: 以下是完整的解决方案:

 <a href="http://stackoverflow.com/questions/11312923/custom-pinterest-button-for-custom-url-text-link-image-or-both" data-image="http%3A%2F%2Fcdn.sstatic.net%2Fstackexchange%2Fimg%2Flogos%2Fso%2Fso-logo.png" data-desc="Custom Pinterest button for custom URL (Text-Link, Image, or Both)" class="btnPinIt" target= "pinIt">
    Custom Pin it image or text here!
</a> 

<script>
$('.btnPinIt').click(function() {
    var url = $(this).attr('href');
    var media = $(this).attr('data-image');
    var desc = $(this).attr('data-desc');
    window.open("//www.pinterest.com/pin/create/button/"+
    "?url="+url+
    "&media="+media+
    "&description="+desc,"pinIt","toolbar=no, scrollbars=no, resizable=no, top=0, right=0, width=750, height=320");
    return false;
});
</script>

Works for me perfectly. 非常适合我。 Your script 你的剧本

 <script>
    function pinIt()
    {
      var e = document.createElement('script');
      e.setAttribute('type','text/javascript');
      e.setAttribute('charset','UTF-8');
      e.setAttribute('src','https://assets.pinterest.com/js/pinmarklet.js?r='+Math.random()*99999999);
      document.body.appendChild(e);
    }
    </script>

Call it with 叫它

<a href="javascript:pinIt();">Pin</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM