Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force a window.onload event in javascript

Tags:

javascript

Ok, I am going to rephrase my request as I think based on some of the answers, it got convoluted. All I am looking for is if there is a javascript command to fire the onload event from the javascript in the parent. A line of code such as: document.getElementById('FrameID').fire.onload(); or if this cannot be done.

I am brainstorming an application where I am going to preload some iframes with url's, say 10 of them. I am then going to rotate them by hiding and displaying the frames. I want to be able to fire a window onload event after the active frame is displayed without reloading the page so the page will act as if it is fresh if it has an onload event. Can I do this? The pages may or may not have a window onload event.

like image 601
user999684 Avatar asked Mar 10 '12 00:03

user999684


1 Answers

This is the current method for re-emitting the load event:

dispatchEvent(new Event('load'));

https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events

Browser compatibility:

  • Chrome: 15+
  • Firefox: 11+
  • Microsoft Edge: all versions
  • Opera: 11.60+
  • Safari: 6+
  • Internet Explorer: none (see Dave's answer)
like image 110
Martin Wantke Avatar answered Oct 27 '22 10:10

Martin Wantke