admin管理员组

文章数量:1207178

I am aware that IE supports the onreadystatechange attribute on the object tag, but this doesn't seem to be a standard way thus all other browsers do not support it.

Update: To clarify, I am not looking for the DOM Load event, I am looking for the load event of the object tag itself(e.g. an object tag embedding a PDF file into a page).

In a way, I am looking for something similar to img's onload event /complete attribute for the object tag.

I am aware that IE supports the onreadystatechange attribute on the object tag, but this doesn't seem to be a standard way thus all other browsers do not support it.

Update: To clarify, I am not looking for the DOM Load event, I am looking for the load event of the object tag itself(e.g. an object tag embedding a PDF file into a page).

In a way, I am looking for something similar to img's onload event /complete attribute for the object tag.

Share Improve this question edited Oct 17, 2011 at 15:13 Hyangelo asked Oct 13, 2011 at 15:14 HyangeloHyangelo 4,8124 gold badges27 silver badges34 bronze badges 5
  • You just made my answer irrelevant with that edit – m.edmondson Commented Oct 13, 2011 at 15:27
  • Anyone? Or is this really just not possible as of the moment? – Hyangelo Commented Oct 14, 2011 at 19:11
  • 1 complete is an event?! Isn't it a flag telling you is the image loading completed or not? – Cipi Commented Oct 17, 2011 at 14:29
  • sorry, I meant the onload event/complete attribute. Updated question. Thanks for the heads up. – Hyangelo Commented Oct 17, 2011 at 15:13
  • Were you able to find a solution for this? – Manoj Reddy Commented Mar 30, 2015 at 9:01
Add a comment  | 

3 Answers 3

Reset to default 5 +50

The <object onload> attribute works well in latest versions of Firefox, Chrome and Opera (I've just tested it).

Also, the expression 'onload' in document.createElement('object') evaluates to true in Chrome and Opera; naturally, Firefox is an exception because such event support check doesn't work there generally. kangax describes cross-browser event support detection at http://perfectionkills.com/detecting-event-support-without-browser-sniffing/

So you want to trigger an event after the [PDF] object is loaded?
If so, this might help you:

http://www.webdeveloper.com/forum/showthread.php?t=160792

----- EDITED [19/10/2011] -----

If you load the PDF inside an iframe, it will work.

Check this: http://sykari.net/stuff/iframe

The script will alert only after the PDF is completely loaded.
(Tested with FF7 + Win7).

----- EDITED [20/10/2011] -----

Using JQuery: http://jsfiddle.net/fcABz

To be sure it is working i have added a 36 pages PDF file to the iframe, so you can watch the progress bar (at least in FF7 there is one, not sure about Chrome) going up, and after it is fully loaded, you will see an alert.

Why? Because the .load method from JQuery will wait until all subelements inside the iframe are loaded.

The load event is sent to an element when it and all sub-elements have been completely loaded. This event can be sent to any element associated with a URL: images, scripts, frames, iframes, and the window object.

If you want to try more then once, clear the cache.
Or change the PDF to a bigger one, like this http://pubs.usgs.gov/tei/532/report.pdf (90 pages).

I'm not sure you can do this just using object attributes.

Have a look at this :

  • You can try something using onreadystatechange

    When data is well loaded, readyState==4 and xmlhttp.status==200

  • You can try to use jQuery load function :

    Export your <object/> in a page called object.html.

    In your main page include :

    <div id="theObject"></div> <script> $("#theObject").load("object.html", function(response, status, xhr) { alert('Loaded : '+status);}); </script>

    The message will be display when the request completes.

本文标签: javascriptIs there a crossbrowser standard onload event for HTML39s quotobjectquot tagStack Overflow