javascript JSP window.open() 函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15053309/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 23:19:07  来源:igfitidea点击:

JSP window.open() function

javascriptjsp

提问by user1791618

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

我正在创建一个 JSP 页面,必须在其中打开一个包含某些内容的新窗口。例子:

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?

当我们使用 Internet Explorer 浏览器时,程序会打开一个“新窗口”。当我们使用 Google Chrome 浏览器时,同一个程序会打开一个“新标签”而不是“新窗口”。这背后的问题是什么?也让我知道解决方案?

回答by ajp15243

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.

请记住,首先,JSP 在服务器端进行评估并输出发送到浏览器的标记,window.open()然后在客户端执行类似(即 JavaScript)之类的东西。

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.

其次,它是打开一个新选项卡还是一个新窗口(如我的评论链接所示)取决于用户在浏览器中的偏好,因此不是您可以控制的。您应该能够在 IE 和 Chrome 中更改您自己的浏览器设置以进行测试。

回答by Derek

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

请注意 window.open 是 JavaScript 函数而不是 JSP,JSP 用于服务器端,JavaScript 用于客户端。

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

要在 chrome 中弹出一个新窗口,您必须指定新窗口的“规格”。这是一个例子。

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

“规格”的更多详细信息,请参阅 w3school http://www.w3schools.com/jsref/met_win_open.asp

Hope this can help you.

希望这可以帮到你。

回答by Suresh Atta

As all said It's an javascriptfucnction. Not jsp's.

正如所有人所说,这是一个javascript功能。不是jsp的。

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

如果您没有设置任何蚂蚁目标,则取决于browser specification.

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

因此,最好提及target attribute摆脱浏览器依赖。

Here is the target list defined by W3C.

这是 W3C 定义的目标列表。

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

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

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

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