【发布时间】:2015-04-26 20:44:33
【问题描述】:
我想检测 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看到
【问题讨论】:
标签: javascript jquery html pdf iframe