I have already introduced the Window.event article about cross iframe, interested can look down,
Http://www.css-js.cn/javascript/ie-iframe-window-event.html
Each elem node of IE has a onreadystatechange event that is triggered each time a change in the Elem content is sent.
For example, content is loading loading will trigger, content loaded loaded will trigger, content load success complete will trigger,
This function also needs to work with readystate, which is an attribute owned by each elem on IE that is used to view the state at each trigger.
|
First add a onreadystatechange iframe.attachevent ("onreadystatechange") to the IFRAME, function () {//This event will also be triggered when the content is not loaded. So we have to judge the state//Sometimes it will be more strange readyState state will skip complete so we loaded state also to judge if (Iframe.readystate = = "complete" | | iframe.readyst ate = = "loaded") {//code can be executed to show here that the success has been loaded///To clear out the event iframe.detachevent ("onReadyStateChange", Arguments.callee); Here is the callback function}}); |
First add a onreadystatechange iframe.attachevent ("onreadystatechange") to the IFRAME, function () {//This event will also be triggered when the content is not loaded. So we have to judge the state//Sometimes it will be more strange readyState state will skip complete so we loaded state also to judge if (Iframe.readystate = = "complete" | | iframe.readystate = = "Loaded") {//code can be executed to show here that the success has been loaded///To clear off the event iframe.detachevent ("onReadyStateChange", Arguments.callee);//Here is the callback function}} ); |
Edit code Reset Run code |
In other non-IE browsers firefox,opera,chrome and other IFRAME will have a onload event, this event as long as the trigger said that the content has been loaded.
|
Iframe.addeventlistener ("Load", function () {//code can be executed here the description has been loaded successfully completed This.removeeventlistener ("Load", Argume Nts.call, false); Here is the callback function}, FALSE); |
Iframe.addeventlistener ("Load", function () {//code can be executed here the description has been loaded successfully completed This.removeeventlistener ("Load", Arguments.call, FALSE); Here is the callback function}, FALSE); |
Edit code Reset Run code |
Note: 1. If the IFRAME is dynamically created, this function must be placed in an IFRAME that is appendchild to the body, otherwise it will not be triggered
2. If it is static IFRAME general onload will not be triggered, causing the same reason is because the iframe loading too fast, so the above method is not suitable.