2

I am working on Sharepoint 2010, I have create one custom button. when user select any row from list and click on custom button then I have fetch one multiple line column html in one variable name 'htmlvar'.

My original html is in string format in 'htmlvar' variable. From this variable I want to find all images and its src and convert its src to base64.

I want to export all this htmlvar in Outlook, so I want to convert image src.

<script type="text/javascript">
var htmlvar =
"<html>
<head>
</head>
<body>
this is my current text
<img alt='apptitle.png' src='/SiteAssets/Lists/BusinessOpp1/EditForm/apptitle.png'/>
this my second text
<img alt='apptitle2.png' src='/SiteAssets/Lists/BusinessOpp1/EditForm/apptitle2.png'/>
</body>
</html>"
 </script>


aspected output is:


<script type="text/javascript">
var htmlvar = "<html>
<head>
</head>
<body>
this is my current text <img alt='apptitle.png' src='data:image/jpeg;base64, LzlqLzRBQ...'/>
this my second text <img alt='apptitle2.png' src='data:image/jpeg;base64, LzlqLzRBQ...'/>
</body>
</html>"
 </script>

Please anyone guide me how can i do in sharepoint 2010

Thanks In Advance

closed as off-topic by Robert Lindgren May 30 '14 at 6:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to SharePoint are off-topic here, but can be asked on Stack Overflow." – Robert Lindgren
If this question can be reworded to fit the rules in the help center, please edit the question.

1

Untitled Page </script>-->

<input type="text" id="test2" />
<script type="text/javascript">        

    var html = "<html><head></head><body>this is my current text <img alt='apptitle.png' src='http://localhost:49480/Desktop/apptitle2.png'/> this my second text <img alt='apptitle2.png' src='http://localhost:49480/Desktop/apptitle.png'/></body></html>"

    var div = document.createElement("div");
    div.innerHTML = html;

    var imgs = div.getElementsByTagName("img");
    var cnt = 0;
    var str = div.innerHTML;


    for (cnt = 0; cnt < imgs.length; cnt++) {

        var img = new Image();
        img.src = imgs[cnt].src;

        img.onload = function () {

            var canvas = document.createElement("canvas");
            canvas.width = this.width;
            canvas.height = this.height;

            var ctx = canvas.getContext("2d");
            ctx.drawImage(this, 0, 0);
            //debugger;
            var path = canvas.toDataURL("image/png|gif|jpg");

            str = str.replace(new RegExp(this.src, 'g'), path);

            document.getElementById("test2").value = (str);
        }
    }

</script>

Please note: 1) Above ans is not support to cross domain 2) IE 9 or above version is support only 3) Not sure about other browser except IE 9 and IE 10

this is my current text <img alt="apptitle.png"  src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPoAAAA/CAYAAADJydU6AAAEvklEQVR4Xu3bX2jVZRzH8c/jztFpUQlKSf8gKG1Q6FohSQamlYwIzYuIRCgvpMZQMxNBHIEg2rY4WATdJBQURNLFWH+GFwtEdI6gC9Ogi6aCZJQQun/Hb7/tIqJx+D3P7/Dgw857sKs9z/d8n9f3fLbD2XOc+EIAgVkv4Gb9CTkgAgiIoPMkQKABBAh6AwyZIyJA0HkOINAAAgS9AYbMEREg6DwHEGgAAYLeAEPmiAgQdJ4DCDSAAEFvgCFzRASCgz5h4/azhvSVjugX/ag/dVkLdace1HJtVIeWqU1lNze4LqNAAIF4AkGBrFrVvtFRfa5ujei8JjXxb2cllXWvHtLLekvt7rWguvGOR2UEEJgSCApkxXbYMX2QxXu8pl5Zc7VBb6rT9QbVZhwIIBBPwDuMJ6zPdqvdu5ND6tOTrt27vndhFiKAQLCAdxA7bY0N67j3A7RqjSruuHd978IsRACBYAHvID5j821M170fwI03acnml7zXsxABBGYKtLS0qKuryzuntQy9C6yzW+26/vaehRstacmWjd7rWYgAAgkEfZett5Pq957FSq3Xe67f+xeJd2EWIoBAsIB3EIdswLZrrfcDvK8Btbm13vW9C7MQAQSCBYKC+JHtsS9V0aiu1XygZi3QJnVqmzsYVDu4czYggIC3QHAYv7VPp8P+q37Sf9+cm6f5ekCPTIf8OfdqcF3vjlmIAALBAsGBnLoCe1andEwf6pzO6Kqu6HYt0lI9ll2UeUMP6wmuwAaPgQ0IxBUIDnrcdqiOAAIxBAh6DFVqIpCYAEFPbCC0g0AMAYIeQ5WaCCQmQNATGwjtIBBDgKDHUKUmAokJEPTEBkI7CMQQIOgxVKmJQGICBD2xgdAOAjEECHoMVWoikJgAQU9sILSDQAwBgh5DlZoIJCZA0BMbCO0gE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ESOgECegE2MZhdmsmuvA/trX5hZ9252YWaXXLm58HtqhTfmHYCfI4CAn8D0Pfe+ndKJyswNq7ZL7d1cgfWjZBUCaQtYdcJ05pPsQy3Zddgr57MPtSyVVmf331u38KGWtEdHdwikI8BL93RmQScIRBMg6NFoKYxAOgIEPZ1Z0AkC0QQIejRaCiOQjgBBT2cWdIJANAGCHo2WwgikI0DQ05kFnSAQTYCgR6OlMALpCBD0dGZBJwhEEyDo0WgpjEA6AgQ9nVnQCQLRBP4BeIHjQMxDZ5cAAAAASUVORK5CYII=" />

  • Please note: 1) Above ans is not support to cross domain 2) IE 9 or above version is support only 3) Not sure about other browser except IE 9 and IE 10 – Kapil Dave Aug 5 '13 at 15:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.