function openBook(bookId) {
var encodedBookId = encodeURIComponent(bookId);
var pdfUrl = "/Home/ReadOnline/?id=" + encodedBookId; // Your PDF API
var pdfViewerUrl = "https://mozilla.github.io/pdf.js/web/viewer.html?file=" + encodeURIComponent(pdfUrl) + "&toolbar=0&view=fitH&statusbar=0&messages=0&navpanes=0";
var iframe = document.getElementById("ReadOnlineframe");
iframe.src = pdfViewerUrl;
// Show the iframe container and loading indicator
document.getElementById("divReadOnlineIframe").style.display = "block";
document.getElementById("Frameloader").style.display = "block";
// Show the modal
$('#mdlReadOnline').modal("show");
// Listen for messages from the iframe (optional)
window.addEventListener("message", function (event) {
if (event.origin !== "https://mozilla.github.io") return; // Ensure it's from the correct source
console.log("Message received from iframe:", event.data);
}, false);
iframe.onload = function () {
var iframeDocument = iframe.contentWindow.document;
// Add style, disable printing and right click, but keep scrolling
var style = iframeDocument.createElement('style');
style.innerHTML = `
@media print { body { display: none !important; } } /* Disable printing */
html, body {
user-select: none;
-webkit-user-select: none;
-moz-user-select: none;
pointer-events: auto; /* Allow scrolling */
overflow: auto; /* Allow scrolling */
}
`;
iframeDocument.head.appendChild(style);
// Disable right click
iframeDocument.addEventListener('contextmenu', function (e) {
e.preventDefault();
});
// Disable shortcut keys (Ctrl+P, Ctrl+S, Ctrl+U)
iframeDocument.addEventListener("keydown", function (e) {
if (e.ctrlKey && (e.key === "p" || e.key === "P" || e.key === "s" || e.key === "u")) {
e.preventDefault();
alert("This operation has been disabled.");
}
});
};
}
Updated code but still same inside iframe its only loading not showing the pdf