There isn't a cross-browser way do focus a tab/window that's 100% reliable, especially in newer browsers. This would be an advertisers dream...so it's actively blocked in most newer browsers.
As a user, I'm glad it's difficult in most cases, impossible in others to do this.