I have a Twitter authorization flow that works perfectly in most browsers. You click “Add a Twitter Account” which has a target="_blank" attribute that sends the user over to Twitter without leaving my site, they authorize, and Twitter sends the user back to a page on my site. That page triggers something with window.opener (the parent window) and then closes the window.
The event is properly triggered on the original window, however there is a case when a user has multiple tabs open in Safari (and maybe other browsers), the new window will open in the last tab, and thus when I execute window.close(), it takes the user to whatever the last tab is now instead of my site. Is there any way to bring the user back to my site aside from removing target="_blank" and going through the flow that way?
No, that’s a browser configuration, and allowing a script to access it would be a security flaw
What you can do is to not use window.open, but rather open it in an iframe.
There’s a lot of jQuery plugins that do this for you, take a look at ThickBox’s iFrame examples