How to determine when pdf is loaded in an iframe when the browser requests partial content requests?

I want to determine when pdf is loaded, but the jQuery .load() event never fires when the browser requests PDF files with partial content requests in Chrome 40.

I want to run the print () function of the browser after downloading pdf. If the PDF is small enough, the browser does not request ranges, but for large pdf files, how can I detect a PDF download?

 function download(src){ var iframe; function check() { console.log('checking..'); if(iframe.contentWindow && iframe.contentWindow.document && iframe.contentWindow.document.body && iframe.contentWindow.document.body.children && iframe.contentWindow.document.body.children.length > 0){ console.log('embed element exists... how do I tell when it\ loaded?'); } else { timeout = setTimeout(check, 150); } } var timeout = setTimeout(check, 150); iframe = $('<iframe type="application/pdf" src="'+src+'"></iframe>').appendTo(document.body).load(function() { console.log('iframe is loaded. This never happens when there are range requests'); }).get(0); } $(document).ready(function(){ download('test.pdf'); }); 

An example can be seen at http://stringham.me/pdf.html

+5
source share
1 answer

This may seem like a dumb answer, but have you tried the onload html attribute?

0
source

Source: https://habr.com/ru/post/1214125/


All Articles