robbestad / react-iframe

Simple solution for using iframes in React
ISC License
436 stars 79 forks source link

how to get onload event? #19

Closed fifyrio closed 6 years ago

fifyrio commented 6 years ago

Hi, buddy, how to get onload event?

rm-rf-etc commented 6 years ago

@fifyrio as it's implemented now, this library won't support it, but if you simply copy the contents of https://github.com/svenanders/react-iframe/blob/master/index.js to your project, you can add support for onLoad. That's what I did, here's the code.

const Iframe = class extends PureComponent {

    render() {

        const props = {
            ref: 'iframe',
            frameBorder: '0',
            src: this.props.url,
            target: '_parent',
            allowFullScreen: this.props.allowFullScreen || false,
            style: Object.assign(
                {
                    position: this.props.position || 'absolute',
                    display: this.props.display || 'block',
                    height: this.props.height || '100%',
                    width: this.props.width || '100%',
                },
                this.props.styles || {},
            ),
            height: this.props.height || '100%',
            name: this.props.name || '',
            width: this.props.width || '100%',
            onLoad: this.props.onLoad ? this.props.onLoad : undefined,
        }

        const { id, className } = this.props

        return React.createElement(
            'iframe',
            Object.assign(props, id ? id : null, className ? className : null),
        )
    }
}
fifyrio commented 6 years ago

Thanks

foxmicha commented 6 years ago

With the merge and release of PR #24 this is now supported.