我在reactjs中有一个代码。我要在我的子组件中打开另一个网址
twitterPopup = () => {
var currentChild = false;
if (currentChild) child.close();
child = window.open(
"http://10.10.1.1:9090/api/v1/twitter/login",
"",
"location=0,toolbar=0,status=0,width=626,height=436"
);
this.props.twitterEvent(true);
timer = setInterval(this.checkChild, 500);
currentChild = true;
};
checkChild = () => {
if (child.closed) {
alert("window closed");
clearInterval(timer);
}
};
如果我重定向我的网址(例如http://localhost:3000?data=234234234432
)
我检查了用 data
检测到的网址 (window.close()
)。
在我的 checkChild
函数中,得到了警报字段。
求助,如何获取父窗口的数据
最佳答案
由于浏览器的安全限制,如果没有其他站点的合作,则无法从第三方子窗口获取数据。
如果您拥有这两个站点,则可以使用 PostMessage API 或 CORS 解决此问题。
关于javascript - 如何在react.JS中将子窗口url获取到父窗口中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60005376/