Javascript: add iframe element after page has loaded -


The best way to add an IFrame element to using Javascript is to find:

    < Li> The user is completely hidden.
  1. The page was created after it was fully loaded. That means that the user should be completely disputed and should not affect the loading of images and other scripts in any way.

    You can add a hidden iframe like this:

      var iframe = document .createElement ('iframe'); Iframe.style.display = "none"; Iframe.src = / * here your url * /; Document.body.appendChild (iframe);  

    If you need to do this on page load, you can put the corresponding code in a script tag at the end of your document, or hook it through the window Can load event ( window.onload = yourFunction; ), though window load event It's too late to load the page process and of course, like many things that involve JavaScript on browsers, If you use RE, like ,,, or, you can make your life a little easier, because it can smooth the difference in the browser (it has been said, the code above will be familiar with any browser I know The library will usually present a way to do things when the page is loaded, but the window load usually returns the JQuery ready function provided Does; Prototype dom: loaded provides the event; e.t.c.

    For example, if you put it at the end of your body tag, then it is loaded after everything and others are all loaded Images, windows load does not occur until all images are loaded):

      & lt; Script type = 'text / javascript' & gt; Window.onload = function () {var iframe = document.createElement ('iframe'); Iframe.style.display = "none"; Iframe.src = / * here your url * /; Document.body.appendChild (iframe); }; & Lt; / Script & gt;  

Comments