1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| bindPaste();
var base64_str = null;
function bindPaste() { var blob; var body = document.getElementsByTagName("body"); var fun = function(e) { var data = e.clipboardData || window.clipboardData; blob = data.items[0].getAsFile(); var isImg = (blob && 1) || -1; var reader = new FileReader(); reader.onload = (function() { return function(e) { console.log("获得粘贴的结果", e.target.result); base64_str = e.target.result; $("#screenShoot").attr("src", base64_str); $("#screenShoot").css("display", "block"); } })(); if (isImg >= 0) { reader.readAsDataURL(blob); } } body[0].removeEventListener('paste', fun); body[0].addEventListener('paste', fun); } $("#sendBtn").on("click", function() { $.ajax({ type: 'get', url: conf.global_url + "/device/saveToImgByStr", data: { base64Str: base64_str, }, cache: false, async: false, dataType: 'json', contentType: 'application/x-www-form-urlencoded;charset=UTF-8', success: function(result) { console.log("result" + result); }, error: function(XMLHttpRequest, textStatus, errorThrown) { console.log('系统异常!'); } }) })
|