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 :: how to handle errors with xmlhttprequest 
Javascript :: sequelize contains 
Javascript :: axios delete request 
Javascript :: divide an array based on length js 
Javascript :: javascript ajax get 
Javascript :: mongodb add 1 to field 
Javascript :: angular ng class with animation 
Javascript :: Sign in with Apple JS 
Javascript :: node red debug to console 
Javascript :: create new component in angular 
Javascript :: es6 concat array 
Javascript :: Country API JavaScript Code 
Javascript :: create or update in sequelize 
Javascript :: parseint function javascript 
Javascript :: window open center 
Javascript :: download xlsx file javascript 
Javascript :: @angular-devkit/build-angular <error 
Javascript :: xmlhttprequest status codes 
Javascript :: react-data-table-component cell action 
Javascript :: isfinite javascript 
Javascript :: to show which tab is active in VueJS 
Javascript :: export table data to excel using javascript or jquery 
Javascript :: get a header from postman repsonse 
Javascript :: react js big calendar 
Javascript :: date format in javascript 
Javascript :: mongoose create text index 
Javascript :: javascript how to do if else 
Javascript :: Remove duplicates from arrays using reduce 
Javascript :: how to use fetch in gatsby 
Javascript :: Toasting a message 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =