Reactjs 要在React中的弹出窗口上显示外部链接页面吗

Reactjs 要在React中的弹出窗口上显示外部链接页面吗,reactjs,iframe,Reactjs,Iframe,我试图在弹出窗口上显示谷歌页面,但它在iframe“www.google.com拒绝连接”中给我消息 App.js import React from 'react'; import Popup from './components/Popup'; class App extends ReactComponent{ constructor(props){ super(props); this.state = { showPopup:false};

我试图在弹出窗口上显示谷歌页面,但它在iframe“www.google.com拒绝连接”中给我消息

App.js

import React from 'react';
import Popup from './components/Popup';

class App extends ReactComponent{

    constructor(props){
        super(props);
        this.state = { showPopup:false};
    }

    togglePopup(){
        this.setState({
            showPopup:!this.state.showPopup
            });
    }

    render(){
        return(
            <div>
            <h1> Simple Popup Example InReact Applicaion </h1>
            <button onClick={this.togglePopup.bind(this)}> Click To Launch Popup </button>

            {this.state.showPopup?
                <Popup
                    text='Click "Close Button" to hide popup'
                    closePopup={this.togglePopup.bind(this)}
                />
            : null
            }
            </div>
        };
    }
}

export default App;
从“React”导入React;
从“./components/Popup”导入弹出窗口;
类应用程序扩展了组件{
建造师(道具){
超级(道具);
this.state={showPopup:false};
}
togglePopup(){
这是我的国家({
showPopup:!this.state.showPopup
});
}
render(){
返回(
反应应用中的简单弹出示例
单击以启动弹出窗口
{this.state.showPopup?
:null
}
};
}
}
导出默认应用程序;
Popup.js


import React from 'react';
import  './style.css';

class Popup extends React.Component{

    render(){
        const google = "<iframe width='100%' height='100%' scrolling='no' src='http://www.google.com' sandbox='allow-modals allow-forms allow-popups allow-scripts allow-same-origin'></iframe>";

        return(
            <div className='popup'>
                <div className='popup_inner'>
                    <h1> {this.props.text} </h1>
                    <div dangerouslySetInnerHTML={{ __html: google ? google :""}}/>
                    <button onClick={this.props.closePopup}> close me </button>
                </div>
            </div>
        );
    }
}

export default Popup;

从“React”导入React;
导入“/style.css”;
类弹出窗口扩展了React.Component{
render(){
const google=“”;
返回(
{this.props.text}
关上我
);
}
}
导出默认弹出窗口;
我的方法不起作用。如果有效的话,我也可以使用其他方法。提前谢谢


首先,为了安全起见,您需要将
http
替换为
https

完成这项工作后,你会得到

Refused to display 'https://www.google.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
它声明谷歌禁止我们使用
https://www.google.com
直接在iframe中


但是,多亏了这一点,您可以使用其他url绕过此限制:(

很好,它可以工作。谢谢。如果我想使用其他url代替“”,该怎么办。例如。或任何其他url?“/webhp?igu=1&gws_rd=ssl”不与其他url一起使用,我猜它是特定于google.com的。这个技巧是特定于google的。你确实需要找到一个可能有效的特定url。但对于Facebook,你也有身份验证,所以我猜它可能会变得棘手