相关疑难解决方法(0)

如何设置反应组件的iframe内容

我试图在React组件中设置iframe的内容,但我无法做到.我有一个组件,其中包含一个函数,当iframe完成加载时必须调用该函数.在该函数中,我正在设置内容,但似乎根本没有调用onload函数.我在chrome浏览器中测试它.我正在尝试以下方法:

var MyIframe = React.createClass({
    componentDidMount : function(){
        var iframe = this.refs.iframe.getDOMNode();
        if(iframe.attachEvent){
            iframe.attacheEvent("onload", this.props.onLoad);
        }else{
            iframe.onload = this.props.onLoad;
        }
    },
    render: function(){
        return <iframe ref="iframe" {...this.props}/>;
    }
});

var Display = React.createClass({
    getInitialState : function(){
        return {
            oasData : ""
        };
    },
    iframeOnLoad : function(){
        var iframe = this.refs.bannerIframe;
        iframe.contentDocument.open();
        iframe.contentDocument.write(['<head></head><style>body {margin: 0; overflow: hidden;display:inline-block;} html{ margin: 0 auto; text-align: center;} body > a > img {max-width: 100%; height: inherit;}', extraCss, '</style></head><body>', this.state.oasData.Ad[0].Text, '</body>'].join(''));
        iframe.contentDocument.close();
    },
    setOasData : function(data){ …
Run Code Online (Sandbox Code Playgroud)

javascript iframe xmlhttprequest reactjs

20
推荐指数
4
解决办法
3万
查看次数

标签 统计

iframe ×1

javascript ×1

reactjs ×1

xmlhttprequest ×1