Files
2026-06-11 18:47:38 +09:00

32 lines
1.7 KiB
JavaScript

document.addEventListener('DOMContentLoaded', function() {
const previewButtons = document.querySelectorAll('.preview-btn');
previewButtons.forEach(button => {
button.addEventListener('click', function() {
// data-content 속성에 base64로 인코딩된 HTML 컨텐츠를 가져옵니다.
const encodedContent = this.dataset.content;
console.log(encodedContent);
if (!encodedContent) {
alert('미리보기할 내용이 없습니다.');
return;
}
try {
// base64로 인코딩된 HTML 컨텐츠를 디코딩합니다.
// atob()는 base64 문자열을 디코딩하고, decodeURIComponent/escape 트릭으로 UTF-8 문자열을 올바르게 처리합니다.
const decodedContent = decodeURIComponent(atob(encodedContent).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
const popup = window.open('', '미리보기', 'width=800,height=600,scrollbars=yes');
// [수정] decodedContent는 이미 완성된 HTML 문서이므로, 추가적인 태그로 감싸지 않고 그대로 출력합니다.
// 이렇게 해야 폼 페이지의 미리보기와 동일하게 작동합니다.
popup.document.write(decodedContent);
popup.document.close();
} catch (e) {
console.error('미리보기 컨텐츠 디코딩 오류:', e);
alert('미리보기 내용을 여는 데 실패했습니다.');
}
});
});
});