简体   繁体   中英

JSP window.open() function

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?

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM