html2canvas.js截屏并上传到后台
$("#example1").on("click",function(event){ if(confirm("是否上传")){ event.preventDefault(); html2canvas($(".jiBMsg"), { crossDomain: true, xhrFields: {withCredentials: true}, allowTaint: true, taintTest: false, background:"#fff", useCORS:true, onrendered: function(canvas) { // alert("111"); canvas.id = "mycanvas"; var dataUrl = canvas.toDataURL("image/jpeg"); // $("body").append('<img src="'+dataUrl+'">'); // var pos = dataUrl.indexOf("4")+2; // dataUrl = dataUrl.substring(pos, dataUrl.length - pos);//去掉Base64:开头的标识字符 $.ajax({ type: "POST", url:url, async: false, data: { 'data': dataUrl}, dataType: "text", success: function (data) { alert(data); }, error: function (err) { console.log(err); } }); } }) } })