Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to convert div to image in jquery

<html><head>    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>    <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script></head><body style="border: 1px solid #808080; width: 550px; height: 350px">    <div id="html-content-holder" style="background-color: #F0F0F1; color: #00cc65; width: 500px; padding-left: 25px; padding-top: 10px;">        <strong>infinetsoft tutorials</strong><hr />        <h3 style="color: #3e4b51;">convert html tocanvas         </h3>        <p style="color: #3e4b51;">            Lorem ipsum dolor sit amet,consectetur adipiscing elit. In scelerisque egestas leo, vel congue maurismattis in. Curabitur quis massa ut metus interdum vehicula in vel massa. Nam miquam, venenatis sit amet libero at, vehicula rutrum nisi. In at aliquam metus.Class aptent taciti sociosqu ad litora torquent per conubia nostra, perinceptos himenaeos. Praesent eget quam laoreet, consequat lacus eget,condimentum neque. Aenean ut vehicula mi, et dictum quam. Integer elementumerat vel sagittis faucibus. Aliquam aliquam, ante et iaculis facilisis, nequeelit tempus neque, et lobortis urna velit porttitor nunc. In rutrum mi sit ametneque porta scelerisque. Pellentesque elementum sapien posuere arcu tinciduntornare. Nullam sed hendrerit nisl. Suspendisse at eros augue. Curabitur tempora lacus nec cursus.        </p>    </div>    <a id="btn-Convert-Html2Image" href="#">convertto image</a>    <script>        $(document).ready(function () {            var element = $("#html-content-holder"); // global variable            var getCanvas; //global variable            html2canvas(element, {                onrendered: function (canvas) {                    getCanvas = canvas;                }            });             $("#btn-Convert-Html2Image").on('click', function () {                var imgageData = getCanvas.toDataURL("image/png");                //Now browser starts downloading it instead of just showing it                var newData = imgageData.replace(/^data:image/png/, "data:application/octet-stream");                $("#btn-Convert-Html2Image").attr("download", "your_image.png").attr("href", newData);            });        });    </script></body></html> 
Comment

PREVIOUS NEXT
Code Example
Javascript :: AJAX JAVASCRIPT FUNCTION CALLS 
Javascript :: get last element in array in javascript 
Javascript :: clearinterval javascript 
Javascript :: js byte size 
Javascript :: how to see my timezone using js 
Javascript :: javascript get clock time in auto counter up 
Javascript :: animate change background color angular 
Javascript :: react select error handle 
Javascript :: how to create an array in javascript 
Javascript :: Remove items from an index position 
Javascript :: props comment 
Javascript :: export socket io connection 
Javascript :: document.queryselector 
Javascript :: react chart js 2 api data 
Javascript :: testing a function in jest on click react 
Javascript :: ckeditor inline editor example 
Javascript :: vanilla js fade in fade out 
Javascript :: chnage classname of div 
Javascript :: react-data-table-component edit action 
Javascript :: how to split by words and punctuation in javascript 
Javascript :: get all files in directory recursively nodejs 
Javascript :: nuxtjs loading 
Javascript :: lexical scope javascript 
Javascript :: js map 
Javascript :: javascript swap 
Javascript :: dynamic forms in react 
Javascript :: js number round to each 15 
Javascript :: onclick increase counter javascript 
Javascript :: Basic Vue JS Setup script for Laravel App 
Javascript :: every in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =