-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
37 lines (34 loc) · 1.27 KB
/
script.js
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
// script.js
document.addEventListener("DOMContentLoaded", () => {
const iframe = document.getElementById("demoIframe");
const pdfUpload = document.getElementById("pdfUpload");
const openPdfButton = document.getElementById("openPdf");
const downloadPdfButton = document.getElementById("downloadPdf");
let uploadedPdfURL = null;
// Handle PDF upload
pdfUpload.addEventListener("change", () => {
const file = pdfUpload.files[0];
if (file && file.type === "application/pdf") {
uploadedPdfURL = URL.createObjectURL(file); // Create URL for the uploaded PDF
} else {
alert("Please upload a valid PDF file.");
pdfUpload.value = ""; // Reset input
}
});
// Open PDF in new tab
openPdfButton.addEventListener("click", () => {
if (uploadedPdfURL) {
iframe.contentWindow.postMessage({ action: "openPdf", data: uploadedPdfURL }, "*");
} else {
alert("Please upload a PDF file first.");
}
});
// Download PDF
downloadPdfButton.addEventListener("click", () => {
if (uploadedPdfURL) {
iframe.contentWindow.postMessage({ action: "downloadPdf", data: uploadedPdfURL }, "*");
} else {
alert("Please upload a PDF file first.");
}
});
});