简体   繁体   中英

How do I prevent mobile devices from automatically downloading a PDF on my website?

So I've got a part on my website where I show a pdf in an iframe. This works perfectly fine on computers. However, some mobile devices start downloading the pdf immediately when they load the website.

This is the code I use.

<div class="showbox" style="display: none;">
    <div class="embed-container">
        <iframe src="/images/pdf-file.pdf" style="border:none;"></iframe>
    </div>
</div>

So I just want the mobile users to be able to visit the website without automatically downloading the pdf.

Any ideas how to pull this off?

how about you use Responsive utility classes ?

take a look at: http://getbootstrap.com/2.3.2/scaffolding.html#responsive

scroll down untill "Responsive utility classes"

you can set your html like this:

<div class="showbox" style="display: none;">
    <div class="embed-container">
    </div>
</div>

and then put this js anywhere:

if( !/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
    $('.showbox .embed-container').append('<iframe src="/images/pdf-file.pdf" style="border:none;"></iframe>');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM