javascript - How to share a data-uri image on Pinterest? -


i want share data-uri image on pinterest.

i've come following markup:

<a target="_blank" href="https://www.pinterest.com/pin/create/button/">   <img class="pin-image" src="data:image/png;base64,…"> </a> 

at end of body including js:

<script   type="text/javascript"   async defer   src="//assets.pinterest.com/js/pinit.js" ></script> 

usually, pinit.js should pick src of img tag inside link, when open link don't see image want share.

i've tried share without pinit.js adding parameters url, data-uri long.

my researches haven't given me helpful advices on sharing generated images on pinterest, on of guys has answer me :-)

you can update anchor tag proper url , avoid loading of pinit.js script..

the basic method trick...

i wrote function you. need pass img selector , find occurrences , apply logic.

demo: https://jsfiddle.net/zmgyc0bd/

function pinterestshareformatter(imgselector) {     var imgs = document.queryselectorall(imgselector),         baseurl = '//www.pinterest.com/pin/create/button/?';      [].foreach.call(imgs, function(img) {     var imgsrc = img.getattribute('src'),         articleurl = img.getattribute('article-url') ? img.getattribute('article-url') : window.location.href, //  check if there article url attribute , if not assign current page url.         parentanchorel = img.parentnode;      // check if parent element <a>     if(parentanchorel.tagname === 'a') {       // format url params       var params = {         url: articleurl,         media: imgsrc       },       paramsstring = object.keys(params).map(function(key){return key + '=' + encodeuricomponent(params[key]);}).join('&');        // update anchor formatted url       parentanchorel.setattribute('href', baseurl + paramsstring);     }   }); }  pinterestshareformatter('.pin-image'); 
  • make sure calling function on right place you.

Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -