window.open is opening new window instead of new tab

html-language

Though in all modern browsers window.open opens a new tab instead of a new window  but in some cases it can still open new window. Like in my case on a particular test machine due to browser plug-in(ad-blocker or similar) installed and it was forcing  to open in new window. And we were told to resolve this issue programmatically, because it was working well in case of Gmail.

I did some research and found that Gmail button click was not calling window.open it was actually an a tag click with target “_blank” so ad blocker was not doing any interruption in that and a new tab was being opened. In our case we were clicking an HTML button.

I did some research for the solution but did not get succeeded. Then I tried to post it on  “Stackoverflow.com” it was already overflowed by similar queries.

Below are few links from there:

  1. http://stackoverflow.com/questions/17339632/how-to-open-new-tab-instead-of-new-window-in-chrome-in-java-scripts
  2. http://stackoverflow.com/questions/6637419/opening-url-in-new-tab
  3. http://stackoverflow.com/questions/9175634/want-to-open-in-new-tab-on-ie8
  4. http://stackoverflow.com/questions/13597452/window-open-opens-new-window-instead-of-new-tab-in-ie8
  5. http://stackoverflow.com/questions/6296013/how-can-i-open-a-link-in-new-tab-and-not-new-window
  6. http://stackoverflow.com/questions/15551779/open-link-in-new-tab
  7. http://stackoverflow.com/questions/8645748/open-url-in-new-tab-instead-of-new-window
  8. http://stackoverflow.com/questions/19031606/open-in-new-tab-instead-of-new-blank-window

but none of them was working in my scenario. In one the above question’s comment some posted that we should create an A tag runtime with target blank and then fire its click event so it should work. But due to some browser security or so it was not working on any machine.

“Every failed attempt/step takes you closer to the success”

That suggestion rewarded me with a solution, Yes! Yes!  ideaI got a solution for this issue.

What we need to do is on button’s click we need to create a form  having target “_blank” and action value as the URL and method =”get” and then submit that.

It worked like a charm. :)

You can find complete solution in a fiddle here http://goo.gl/yd0yJK .