Search code examples
javascriptnode.jsreactjsreact-reduxtwitter-oauth

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. 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. 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


Solution

  • You can open in new window with window.open by setting the target as _blank. Also, it will return an pop-up instance so you can store it in you state and close it whenever you want.

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