Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Darkscribes Community

migelammon@community.nodebb.orgM

[email protected]

@[email protected]
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

View Original

Posts

Recent Best Controversial

  • Need solution that ensures PDFs can be previewed
    migelammon@community.nodebb.orgM [email protected]

    I have written the following JavaScript code to allow students to preview PDF files uploaded to our forum. Our goal is to enable them to view lecture notes directly on the forum while preventing them from downloading the files.

    However, since the PDFs are embedded within an iframe, I haven't been able to completely block the "Save As" option. Even though previewing works fine, students can still download the PDF files, especially on mobile devices where the "Save to Files" option appears.

    I need a solution that ensures PDFs can be previewed but not downloaded on both desktop and mobile devices. How can I achieve this? Thank you.

    $(document).ready(function () {
        function processPDFs() {
            console.log("PDF önizleme işleniyor...");
     
            $('a[href$=".pdf"]').each(function () {
                let link = $(this).attr('href');
     
                if (!$(this).next('.pdf-container').length) {
                    if (isMobileDevice()) {
                        // 📱 **Mobil cihazlarda sadece PDF linkini göster, önizleme yok**
                        $(this).show();
                    } else {
                        // 💻 **Masaüstünde PDF'yi önizle**
                        $(this).hide(); // PDF linkini gizle
     
                        let container = $('<div class="pdf-container" style="width:100%;max-width:900px;height:700px;position:relative;margin-top:10px;border:1px solid #ccc;overflow:hidden"></div>');
                        let pdfObject = $('');
                        let fullscreenBtn = $('<button class="fullscreen-toggle" style="position:absolute;top:10px;right:10px;background:#000;color:#fff;border:none;padding:5px 10px;cursor:pointer;z-index:10">🔍 Tam Ekran</button>');
     
                        pdfObject.attr('data', link + "#toolbar=0");
     
                        fullscreenBtn.on('click', function () {
                            toggleFullscreen(container[0]);
                        });
     
                        container.append(pdfObject).append(fullscreenBtn);
                        $(this).after(container);
                    }
                }
            });
     
            $('.file a').each(function () {
                let fileLink = $(this).attr('href');
                if (fileLink.endsWith('.pdf') &amp;&amp; !$(this).next('.pdf-container').length) {
                    if (isMobileDevice()) {
                        // 📱 **Mobilde sadece PDF linki göster**
                        $(this).show();
                    } else {
                        // 💻 **Masaüstünde PDF'yi önizle**
                        $(this).hide();
     
                        let container = $('<div class="pdf-container" style="width:100%;max-width:900px;height:700px;position:relative;margin-top:10px;border:1px solid #ccc;overflow:hidden"></div>');
                        let pdfObject = $('');
                        let fullscreenBtn = $('<button class="fullscreen-toggle" style="position:absolute;top:10px;right:10px;background:#000;color:#fff;border:none;padding:5px 10px;cursor:pointer;z-index:10">🔍 Tam Ekran</button>');
     
                        pdfObject.attr('data', fileLink + "#toolbar=0");
     
                        fullscreenBtn.on('click', function () {
                            toggleFullscreen(container[0]);
                        });
     
                        container.append(pdfObject).append(fullscreenBtn);
                        $(this).after(container);
                    }
                }
            });
        }
     
        // 📌 **Mobil Cihaz Algılama**
        function isMobileDevice() {
            return /Mobi|Android|iPhone|iPad|iPod/i.test(navigator.userAgent);
        }
     
        // 📌 Tam Ekran Aç/Kapat Fonksiyonu
        function toggleFullscreen(element) {
            if (!document.fullscreenElement &amp;&amp; !document.mozFullScreenElement &amp;&amp; !document.webkitFullscreenElement &amp;&amp; !document.msFullscreenElement) {
                if (element.requestFullscreen) {
                    element.requestFullscreen();
                } else if (element.mozRequestFullScreen) {
                    element.mozRequestFullScreen();
                } else if (element.webkitRequestFullscreen) {
                    element.webkitRequestFullscreen();
                } else if (element.msRequestFullscreen) {
                    element.msRequestFullscreen();
                }
            } else {
                if (document.exitFullscreen) {
                    document.exitFullscreen();
                } else if (document.mozCancelFullScreen) {
                    document.mozCancelFullScreen();
                } else if (document.webkitExitFullscreen) {
                    document.webkitExitFullscreen();
                } else if (document.msExitFullscreen) {
                    document.msExitFullscreen();
                }
            }
        }
     
        // 📌 ESC ile Tam Ekrandan Çıkınca Butonu Güncelle
        $(document).on("fullscreenchange mozfullscreenchange webkitfullscreenchange msfullscreenchange", function () {
            $(".fullscreen-toggle").text(document.fullscreenElement ? "↩ Tam Ekrandan Çık" : "🔍 Tam Ekran");
        });
     
        // İlk yükleme
        processPDFs();
     
        // Sayfa değişimlerinde tekrar çalıştır (NodeBB SPA yapısına uygun)
        $(window).on('action:ajaxify.end', function () {
            processPDFs();
        });
     
        console.log("PDF izleme sistemi güncellendi: Mobilde sadece link gösteriliyor, masaüstünde önizleme aktif.");
    });
    
    Uncategorized
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups