Javascript – Only load HTML into an IFRAME

domhtmliframejavascript

How can I only load the HTML of a page into an IFRAME, without automatically triggering the download of all the css,scripts,images,videos on the page?

Or can you get an event the moment the DOM is "ready".. when the initial HTML has loaded and nothing much more.

Best Solution

There is no cross-browser way to do this. Some browsers provide events that fire when the DOM loads, like DOMContentLoaded for Gecko.

jQuery implements this functionality. I suggest you either use jQuery for this:

$(document).ready(function () {
  // Function is called when the DOM is loaded.
});

Or check how jQuery implements it. See the bindReady function in the jQuery source code.