简体   繁体   English

如何从反应前端应用程序打开新选项卡

[英]How to open a new tab from a react front-end app

Okay so what I am trying to do is create a twitter front-end application that allows users to post tweets.好的,我想做的是创建一个允许用户发布推文的 twitter 前端应用程序。 The problem I'm having is during the 3-legged Auth sequence, I get a response from the twitter api in form of a html and I need to open that response data in a new window so the user can accept whatever it is and allow my app to access their account. The problem I'm having is during the 3-legged Auth sequence, I get a response from the twitter api in form of a html and I need to open that response data in a new window so the user can accept whatever it is and allow我的应用程序来访问他们的帐户。 Could someone point me in the right direction.有人可以指出我正确的方向。 I don't want to get into building a backend to do solve this as I'm trying to keep this a solely react application.我不想建立一个后端来解决这个问题,因为我试图保持它是一个单独的反应应用程序。

Thanks谢谢

You can open in new window with window.open by setting the target as _blank.通过将目标设置为 _blank,您可以使用 window.open 在新的 window 中打开。 Also, it will return an pop-up instance so you can store it in you state and close it whenever you want.此外,它将返回一个弹出实例,因此您可以将其存储在 state 中,并随时关闭它。

 const popup = window.open(twitterUrl, '_blank', 'width: 580px, height: 690px'); popup.close() // when you need it

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM