Skip to content Skip to sidebar Skip to footer

Create An Iframe Then Append Data To It With Jquery

I am trying do some modification to an greasemonkey userscript to implement a feature I need. The code is like showAddress:function(addrString,type) { this.addrBox=$('

Solution 1:

Since you are adding the iFrame in the same domain, then you can manipulate its contents like this: (See it in action at jsBin.)

$("#batchContent").append ('<iframe id="batchedlink"></iframe>');

/*--- Compensate for a bug in IE and FF, Dynamically added iFrame needs 
    some time to become "DOM-able".
*/setTimeout ( function () {
        var iframeBody  = $("#batchedlink").contents ().find ("body");

        iframeBody.append (addrString);
    },
    333
);

NOTE: For a Chrome userscript, you apparently don't need the timer delay. But for FF and IE 8 (the other 2 browsers I double-checked), a dynamically added iFrame is not manipulable until after it has "settled" for some reason. This seems to take about 200 mS.

A statically loaded iFrame does not have this lag, see the jsBin demo.

Solution 2:

Sort of hard to tell exactly what you're asking -- but if you want to know whether or not you can append DOM elements to an iFrame, the answer is "no".

Post a Comment for "Create An Iframe Then Append Data To It With Jquery"