JS实现页面截图并下载图片到本地

  

      

          

            

        

        

           

          

        $(document).ready( function(){  

                $(".example1").on("click", function(event) {  

                        event.preventDefault();  

                        html2canvas(document.body, {  

                        allowTaint: true,  

                        taintTest: false,  

                        onrendered: function(canvas) {  

                            canvas.id = "mycanvas";  

                            //document.body.appendChild(canvas);  

                            //生成base64图片数据  

                            var dataUrl = canvas.toDataURL();  

                            var newImg = document.createElement("img"); 

                            newImg.className = 'myjietuimg' 

                            newImg.src =  dataUrl;  

                            document.body.appendChild(newImg);  

                            alert('截图已生成,可以下载!')

                        }  

                    });  

                });   


        });  


          

        

      

      

        Hello World!  

          

            奥利给,干了兄弟们  

            
关注我  

        

  

        

        

        

        

        

        生成图片 

        下载图片 

      

  

你可能感兴趣的:(JS实现页面截图并下载图片到本地)