Javascript 如何使用javascript打开新的浏览器窗口?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3616709/
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-08-23 05:27:02  来源:igfitidea点击:

How to open new browser window using javascript?

javascript

提问by Rose

I need to open new browser window using java script window.open, i have html page but it getting error as page not found.This is from jsf/icefaces.I have display the html page directly.Please help me...

我需要使用 java 脚本 window.open 打开新的浏览器窗口,我有 html 页面,但由于找不到页面而出现错误。这是来自 jsf/icefaces。我直接显示了 html 页面。请帮助我...

    JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(),
"window.open('printerFriendly.html','Print',,'width=300','height=200','menubar=yes',
'status=yes','location=yes','toolbar=yes','scrollbars=yes')");

回答by Marcin Cylke

Try something like this:

尝试这样的事情:

<FORM>
<INPUT type="button" value="New Window!" onClick="window.open('http://stackoverflow.com','mywindow','width=400,height=200,toolbar=yes,
location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,
resizable=yes')">
</FORM> 

It's in a form, but the JS code would be the same for any other link.

它是一种形式,但任何其他链接的 JS 代码都是相同的。

回答by ratty

Opening a New Window With JavaScript

用 JavaScript 打开一个新窗口

http://www.pageresource.com/jscript/jwinopen.htm

http://www.pageresource.com/jscript/jwinopen.htm

Javascript (JS) Tutorial - opening new browser window using open ...

Javascript (JS) 教程 - 使用 open ... 打开新的浏览器窗口

http://www.hscripts.com/tutorials/javascript/open-method.php

http://www.hscripts.com/tutorials/javascript/open-method.php

回答by Alex Reitbort

window.open opens new browser window. If you getting page not found error, may be you should check that the page exists?

window.open 打开新的浏览器窗口。如果您收到未找到页面的错误,您是否应该检查该页面是否存在?

回答by slikts

Your JavaScript is correct, you need to correct the URL ('printerFriendly.html').

您的 JavaScript 是正确的,您需要更正 URL ('printerFriendly.html')。

回答by Strelok

Page Not Found is Page Not Found. Check if the URL is correct. Is printerFriendly.htmllocated in the same folder as your current page? It should be. Or you should provide the correct path.

未找到页面是未找到页面。检查网址是否正确。是否printerFriendly.html与当前页面位于同一文件夹中?它应该是。或者您应该提供正确的路径。