2016-07-29 24 views
0

我曾經在我的博客如何使Pinterest的按鈕搶真實大小的博客圖像,而不是縮略圖

<li><a class='pinterest share-tooltip share-tooltip-top' data-share-tooltip='Share on Pinterest' expr:href='&quot;http://pinterest.com/pin/create/button/?url=&quot; + data:post.url + &quot;&amp;media=&quot; + data:post.firstImageUrl + &quot;&amp;description=&quot; + data:post.title' target='_blank'><i class='fa fa-pinterest'/>Pinterest</a></li> 

這個Pinterest的按鈕,你可以看到我使用數據:post.firstImageUrl爲圖像的來源...但問題是我使我的拳頭圖像不顯示在一個完整的大小隻有一個縮略圖(中等大小)...所以當我用這個數據:post.firstImageUrl。 ..只有縮略圖才能共享的圖像不是真正的圖像

這裏是縮略圖URL樣本這是我從得到數據:post.firstImageUrl

https://3.bp.blogspot.com/-W-g2qYS-Kh0/V5gs0FvhpKI/AAAAAAAAFSY/yh_3p00aSA4-fRa65NH4cQ83iEngZhDeACLcB/s640/BMW-M5-30-Jahre-2014-1.jpg 

,這裏是全尺寸圖像的URL,我想

https://3.bp.blogspot.com/-W-g2qYS-Kh0/V5gs0FvhpKI/AAAAAAAAFSY/yh_3p00aSA4-fRa65NH4cQ83iEngZhDeACLcB/s1600/BMW-M5-30-Jahre-2014-1.jpg 

你可以看到不同的只有來到這個部分xxx:// xxx/xxx/s640/xxx and xxx:// xxx/xxx/s1600/xxx ...

我的問題是如何改變這個URL部分S640這個S1600以及如何將其分配到我Pinterest的按鈕?

我已經看到使用JavaScript來改變這個URL部分人/ S640 /,他用它來自動調整縮略圖,我不熟悉JavaScript,所以我真的不明白,這裏是代碼

img src="'+image_url.replace('/s72-c/','/s'+image_size+'-c/')+'" alt="'+post_title+'"/ 
+0

您可以在jsbin/jsfiddle中提供一個工作示例嗎? – MattDiMu

回答

0

您可以使用this pastie的腳本。但它需要一點改變。

<script type='text/javascript'> 
//<![CDATA[ 
function thumbnail_resize(image_url) { 
    var image_size = 1600; 
    image_tag = image_url.replace('/s640/','/s' + image_size + '/'); 
    if(image_url != "") { 
    return image_tag; 
    } else { 
    return ""; 
    } 
} 
//]]> 
</script> 

這裏我們替換了圖像的URL。

<script type='text/javascript'>document.write('&lt;a class=&quot;pinterest share-tooltip share-tooltip-top&quot; data-share-tooltip=&quot;Share on Pinterest&quot; href=&quot;http://pinterest.com/pin/create/button/?url=<data:post.url/>&amp;media=' + thumbnail_resize(&quot;<data:post.firstImageUrl/>&quot;) + '&amp;description=<data:post.title/>&quot;&gt;PING&lt;/a&gt;');</script> 

在這裏,我們通過JavaScript粘貼鏈接。

+0

謝謝,謝謝,這真的很有用... – shirohige

相關問題