简体   繁体   中英

Use jQuery to get a PDF load ready state

I have an embedded pdf using an object tag. I want to know when the object's readyState==4 (or whatever)

I find jQuery's ready() but that looks like it only works on document load.

Other code out there seems to just loop through checking the ready sate, but that seems a little hacky to me.

Is there a nice clean way to do something like:

$("#pdfObject").onStateChange = function(state) {
   if(state==4) ....
}

you get the idea.

A simple solution (tested in Chrome and FF) would be to embed the pdf in an iframe and listen for the iframe's load event (shown inline for simplicity). However, this does not seem to work in IE, so if I were you, I'd just stick to polling for readyState

<iframe 
    src="http://www.epa.gov/region10/pdf/ph/sitewide/bera_draft_final_7-1-2011.pdf"
    onload="alert('done')"></iframe>

http://jsfiddle.net/8x5AA/

jQuery不知道pdf文档是否已加载,我建议您使用另一个可以帮助您处理PDF文档的库,检查您的http://pdfobject.com/,然后通过调用来确定是否已渲染该文档

PDFObject.embed(targetID)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM