연구의 시간 후에, 나는 마침내 심지어 origin-clean
FLAG가있는 경우, 요소의 화면을 캡처 할 수있는 해결책을 발견 (XSS를 방지하기 위해) 설정 되었기 때문에 Google지도를 캡처 할 수 있습니다 (필자의 경우). 나는 스크린 샷을 얻는 보편적 인 함수를 썼다. 추가로 필요한 것은 html2canvas 라이브러리 (https://html2canvas.hertzen.com/)뿐입니다.
예 :
getScreenshotOfElement($("div#toBeCaptured").get(0), 0, 0, 100, 100, function(data) {
// in the data variable there is the base64 image
// exmaple for displaying the image in an <img>
$("img#captured").attr("src", "data:image/png;base64,"+data);
}
염두 console.log()
곳에 화상의 크기가 큰 경우 alert()
이뤄져는 출력을 생성한다.
기능 : 이해가 안
function getScreenshotOfElement(element, posX, posY, width, height, callback) {
html2canvas(element, {
onrendered: function (canvas) {
var context = canvas.getContext('2d');
var imageData = context.getImageData(posX, posY, width, height).data;
var outputCanvas = document.createElement('canvas');
var outputContext = outputCanvas.getContext('2d');
outputCanvas.width = width;
outputCanvas.height = height;
var idata = outputContext.createImageData(width, height);
idata.data.set(imageData);
outputContext.putImageData(idata, 0, 0);
callback(outputCanvas.toDataURL().replace("data:image/png;base64,", ""));
},
width: width,
height: height,
useCORS: true,
taintTest: false,
allowTaint: false
});
}
. 렌더링 된 DIV의 스크린 샷을 만들어 이미지에 저장 하시겠습니까? –
더 나은 질문 ... ** ** 왜 이걸하고 싶니? 나중에 다시로드하기 위해 UI의 "상태"를 저장하려고합니까? .innerHTML은 IE에서 유효하지 않은 태그 수프를 반환하며 모든 브라우저에서 외부 소스 (CSS와 JavaScript 모두)의 스타일링에 관한 정보는 포함하지 않습니다. – scunliffe
이전 질문 이었지만 그렇게할만한 이유가 있습니다. . 특히 하이브리드 애플 리케이션의 현대 시대에. – Wtower