iframe / jquery .toggle fails to hide .pdf in Safari

前端 未结 1 1292
一向
一向 2021-01-24 13:41

I have an iFrame with a pdf src. When I click a button it is shown. When I click a button it is hidden.

It is coded as a function using jquery .toggle (simplified):

相关标签:
1条回答
  • 2021-01-24 14:33

    Here is the solution:

    • preload the .pdf in a hidden iframe
    • toggle iframe and visibility as before
    • add the src to the original iframe using jquery

    JS-Fiddle: http://jsfiddle.net/hT97Z/3/

    In this way the loading of the .pdf is isolated from the toggle function all together.


    The code added to the function:

    function showpdf() { $('.showpdf').toggle(); $('#theframe').attr('src','the.pdf'); }
    

    The html added:

    <iframe style="display:none;" src="the.pdf"></iframe>
    
    0 讨论(0)
提交回复
热议问题