使用jQuery更新Pinterest配置文件小部件中的链接

使用jQuery更新Pinterest配置文件小部件中的链接,jquery,href,pinterest,Jquery,Href,Pinterest,我一直在尝试使用jQuery更新生成的Pinterest概要文件小部件中的链接。代码是通过Pinterest为我的客户网站生成的 这是嵌入的代码: <a data-pin-do="embedUser" href="http://www.pinterest.com/aliceandlois/" data-pin-scale-width="155" data-pin-scale-height="130" data-pin-board-width="985"></a> 然后生

我一直在尝试使用jQuery更新生成的Pinterest概要文件小部件中的链接。代码是通过Pinterest为我的客户网站生成的

这是嵌入的代码:

<a data-pin-do="embedUser" href="http://www.pinterest.com/aliceandlois/" data-pin-scale-width="155" data-pin-scale-height="130" data-pin-board-width="985"></a>
然后生成的代码如下所示:

<a class="PIN_1425163222617_embed_grid_th" title="Pom Pom Wall Hanging &mdash; Simple to make and so cute!" data-pin-href="//www.pinterest.com/pin/452963674997848977/repin/x/" data-pin-id="452963674997848977" data-pin-log="embed_user_thumb" style="height: 130px; width: 155px; top: 0px; left: 0px;"><img src="http://media-cache-ak0.pinimg.com/237x/cd/4d/74/cd4d749b360486b0fd4706f1a068c5ce.jpg" data-pin-nopin="true" class="PIN_1425163222617_embed_grid_img" alt="Pom Pom Wall Hanging &amp;#8212; Simple to make and so cute!" style="height: 232.173px; width: 155px; min-height: 232.173px; min-width: 155px; margin-top: -116.086px;"></a>
我试图做的是更新data pin href中的URL以删除URL中的repin/x/部分,例如,它的内容是://www.pinterest.com/pin/452963674997848977/而不是//www.pinterest.com/pin/452963674997848977/repin/x/

这需要为小部件中的每个图像自动完成,其中有20个图像

为了实现这一点,我已经尝试使用发布在的教程,但是,我无法使用数据pin href属性而不是标准href

我还发现这个JSFIDLE可能对我有所帮助,因此我将代码修改为Nessery,但仍然没有乐趣:

有人能帮我解决这个问题吗

谢谢

编辑:我一直在研究如何解决这个问题,但仍然没有乐趣。我在尝试解决方案时参考了以下链接:


经过几次尝试后,我自己设法解决了这个问题

我尝试的最终代码的初始版本如下:

$('.pinterest-block a[data-pin-href]').each(function(){
    var newurl = $(this).attr('data-pin-href').replace('repin/x/','');
    $(this).attr('data-pin-href', newurl);
});
虽然这在我对JSFIDLE的测试中起到了作用,但我感到困惑的是,当我尝试对实时代码进行测试时,它并没有起作用

我确定问题出在一定程度上与您必须嵌入代码中的Pinterest脚本文件有关:

当文档准备就绪并替换以下内容时,脚本将运行:

<a data-pin-do="embedUser" href="http://www.pinterest.com/aliceandlois/" data-pin-scale-width="155" data-pin-scale-height="130" data-pin-board-width="985"></a>
这就解决了这个问题,因为数据pin href现在可以根据我的需要进行更新

如果有人对我的解决方案有一个更精简的版本,请随时发布,但是,我不相信它可以进一步压缩

JSFiddle:

window.setTimeout(function (){
        $('.pinterest-block a[data-pin-href]').each(function(){
            var newurl = $(this).attr('data-pin-href').replace('repin/x/','');
            $(this).attr('data-pin-href', newurl);
        });
    }, 1500);