簡體   English   中英

如何在瀏覽器請求部分內容范圍請求時檢測何時在iframe中加載pdf?

[英]How to detect when pdf is loaded in iframe when browser requests partial content range requests?

我想檢測pdf何時加載,但是當瀏覽器在Chrome 40中請求帶有部分內容范圍請求的pdf時,jQuery .load()事件永遠不會觸發。

我想在pdf加載后觸發瀏覽器print()函數。 如果pdf足夠小,瀏覽器不會請求范圍,但對於較大的pdf,我如何檢測pdf加載?

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\'s 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');
});

可以在http://stringham.me/pdf.html上看到一個示例

這可能聽起來像一個愚蠢的答案,但你嘗試過onload html屬性嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM