Rya*_*yan 5 html javascript pdf iframe jquery
我想检测pdf何时加载,但是.load()当浏览器在Chrome 40中请求带有部分内容范围请求的pdf时,jQuery 事件永远不会触发.
我想在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');
});
Run Code Online (Sandbox Code Playgroud)
可以在http://stringham.me/pdf.html上看到一个示例
| 归档时间: |
|
| 查看次数: |
812 次 |
| 最近记录: |