1
myIFrame = new IFrame({
    id: 'iframe_content',
    src: '/iframe_src/'
});
console.dir(myIFrame);
var n = new Element('div', {
    style: {
        'width': '100px',
        'height': "100px",
        'border': '1px solid red'
    }
});

myIFrame.inject(document.body);
console.log("innerhtml", myIFrame.contentDocument.body.innerHTML);
console.dir(myIFrame.contentDocument.body);
n.inject(myIFrame.contentDocument.body);

div 没有注入到 iframe 中,并且无法访问 Ifrane 中的任何元素。我如何在 mootools 1.4.0 或 MooTools 1.2 中做到这一点

4

1 回答 1

3

当它涉及混合内容时,这会稍微复杂一些,即src=动态构建的内容和附加 DOM 元素。

iframe 将有一个load事件,当 src 内容被拾取时触发。

http://jsfiddle.net/dimitar/AEP8T/

var myIFrame = new IFrame({
    id: 'iframe_content',
    src: 'http://fiddle.jshell.net/_display/',
    styles: {
        width: 640,
        height: 480
    },
    events: {
        load: function() {

            var n = new Element('div', {
                text: "hai there",
                styles: {
                    'width': '100px',
                    'height': "100px",
                    'border': '1px solid red'
                }
            });

            n.inject(this.contentDocument.body);

        }
    }
}).inject(document.body);

这仅在 src 和 embed 上下文位于同一域/端口等时才有效。

于 2012-07-23T11:12:10.693 回答