0

I am creating a JSP page in which a new window must be opened with some content. Example:

window.open("www.stackoverflow.com");

The program opens a "new window" when we use Internet Explorer browser. The same program opens a "new tab" not "new window" when we use Google Chrome browser. What is the problem behind this? Also let me know the solution?

ajp15243
  • 7,704
  • 1
  • 32
  • 38
user1791618
  • 173
  • 1
  • 4
  • 12
  • Possible duplicate: http://stackoverflow.com/questions/726761/javascript-open-in-a-new-window-not-tab – ajp15243 Feb 24 '13 at 15:36

3 Answers3

2

Remember, first, that JSPs are evaluated server-side and spit out markup that is sent to the browser, where something like window.open() (which is JavaScript) is then executed client-side.

Second, whether it opens a new tab or a new window is (as my comment's link indicates) dependent upon the user's preferences in their browser, and as such is not anything you can control. You should be able to change your own browser settings in IE and Chrome to test this.

ajp15243
  • 7,704
  • 1
  • 32
  • 38
2

Please note that window.open is JavaScript function but not JSP, JSP is for server side and JavaScript is for client side.

For popping up a new window in chrome, you have to specify the "specs" of the new window. Here is an example.

window.open("www.stackoverflow.com", "", "toolbar=yes,menubar=no,resizable=yes,scrollbars=yes,width=1024");

For more details of the "specs", please refers to w3school http://www.w3schools.com/jsref/met_win_open.asp

Hope this can help you.

Derek
  • 2,695
  • 1
  • 16
  • 17
  • This code is causing both Chrome and IE9 to treat it like a popup for me, which users likely have blocked by default. The end result is that it is still dependent upon user settings that the website has no control over. – ajp15243 Feb 24 '13 at 15:48
1

As all said It's an javascript fucnction. Not jsp's.

If you did'nt set any ant target it depends on the browser specification.

So ,it always better to mention the target attribute to get rid off browser dependency .

Here is the target list defined by W3C.

http://www.w3schools.com/tags/att_a_target.asp

Ex:window.open("www.stackoverflow.com","_self");//Always opens in same tab

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307