菜单
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

JS 参考手册

按类别划分的 JS 按字母划分的 JS

JavaScript

JS 数组 JS 布尔值 JS 类 JS 日期 JS 错误 JS 全局 JS JSON JS Map JS Math JS 数字 JS 对象 JS 运算符 JS 优先级 JS Promise JS 正则表达式 JS Set JS 语句 JS 字符串 JS TypedArray

Window

Window 对象 Window Console Window History Window Location Window Navigator Window Screen

HTML DOM

HTML 文档 HTML 元素 HTML 属性 HTML 集合 HTML NodeList HTML DOMTokenList HTML 样式
alignContent alignItems alignSelf animation animationDelay animationDirection animationDuration animationFillMode animationIterationCount animationName animationTimingFunction animationPlayState background backgroundAttachment backgroundClip backgroundColor backgroundImage backgroundOrigin backgroundPosition backgroundRepeat backgroundSize backfaceVisibility border borderBottom borderBottomColor borderBottomLeftRadius borderBottomRightRadius borderBottomStyle borderBottomWidth borderCollapse borderColor borderImage borderImageOutset borderImageRepeat borderImageSlice borderImageSource borderImageWidth borderLeft borderLeftColor borderLeftStyle borderLeftWidth borderRadius borderRight borderRightColor borderRightStyle borderRightWidth borderSpacing borderStyle borderTop borderTopColor borderTopLeftRadius borderTopRightRadius borderTopStyle borderTopWidth borderWidth bottom boxShadow boxSizing captionSide caretColor clear clip color columnCount columnFill columnGap columnRule columnRuleColor columnRuleStyle columnRuleWidth columns columnSpan columnWidth counterIncrement counterReset cssFloat cursor direction display emptyCells filter flex flexBasis flexDirection flexFlow flexGrow flexShrink flexWrap font fontFamily fontSize fontStyle fontVariant fontWeight fontSizeAdjust height isolation justifyContent left letterSpacing lineHeight listStyle listStyleImage listStylePosition listStyleType margin marginBottom marginLeft marginRight marginTop maxHeight maxWidth minHeight minWidth objectFit objectPosition opacity order orphans outline outlineColor outlineOffset outlineStyle outlineWidth overflow overflowX overflowY padding paddingBottom paddingLeft paddingRight paddingTop pageBreakAfter pageBreakBefore pageBreakInside perspective perspectiveOrigin position quotes resize right scrollBehavior tableLayout tabSize textAlign textAlignLast textDecoration textDecorationColor textDecorationLine textDecorationStyle textIndent textOverflow textShadow textTransform top transform transformOrigin transformStyle transition transitionProperty transitionDuration transitionTimingFunction transitionDelay unicodeBidi userSelect verticalAlign visibility width wordBreak wordSpacing wordWrap widows zIndex

HTML 事件

HTML 事件 HTML 事件对象 HTML 事件属性 HTML 事件方法

Web API

API Canvas API Console API Fetch API Fullscreen API 地理位置 API History API MediaQueryList API Storage API 验证 API Web

HTML 对象

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

其他参考

CSSStyleDeclaration JS 转换


Window open()

示例 1

在新浏览器选项卡中打开 "www.w3schools.com"

window.open("https://w3schools.org.cn");
自己动手试一试 »

更多示例见下文。


描述

open() 方法根据您的浏览器设置和参数值,打开一个新的浏览器窗口或一个新的选项卡。

另请参阅

close() 方法.


语法

window.open(URL, name, specs, replace)

参数

参数 描述
URL 可选。
要打开的页面的 URL。
如果未指定 URL,则会打开一个新的空白窗口/选项卡
name 可选。
窗口的 target 属性或名称。
支持以下值
描述
_blankURL 加载到新窗口或选项卡中。这是默认值
_parentURL 加载到父框架中
_selfURL 替换当前页面
_topURL 替换任何可能加载的框架集
name窗口的名称(不指定窗口的标题)
specs 可选。
逗号分隔的项目列表,没有空格。
支持以下值
fullscreen=yes|no|1|0 是否以全屏模式显示浏览器。默认值为 no。处于全屏模式的窗口也必须处于影院模式。仅限 IE
height=pixels 窗口的高度。最小值为 100
left=pixels 窗口的左侧位置。不允许负值
location=yes|no|1|0 是否显示地址栏。仅限 Opera
menubar=yes|no|1|0 是否显示菜单栏
resizable=yes|no|1|0 窗口是否可调整大小。仅限 IE
scrollbars=yes|no|1|0 是否显示滚动条。仅限 IE、Firefox 和 Opera
status=yes|no|1|0 是否添加状态栏
titlebar=yes|no|1|0 是否显示标题栏。除非调用应用程序是 HTML 应用程序或受信任的对话框,否则此项将被忽略
toolbar=yes|no|1|0 是否显示浏览器工具栏。仅限 IE 和 Firefox
top=pixels 窗口的顶部位置。不允许负值
width=pixels 窗口的宽度。最小值为 100
replace

已弃用

指定 URL 是在历史列表中创建新条目还是替换当前条目。支持以下值
  • true - URL 替换历史列表中的当前文档
  • false - URL 在历史列表中创建新条目

警告

Chrome 在使用此参数时会抛出异常。

来源:Bugs Chromium Issue 1164959

返回值

新窗口的引用,如果调用失败,则为 null


更多示例

在新窗口/选项卡中打开 about:blank 页面

var myWindow = window.open("", "", "width=200,height=100");
自己动手试一试 »

打开一个名为 "MsgWindow" 的新窗口,并在其中写入一些文本

var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>这是 'MsgWindow'。我宽 200px,高 100px!</p>");
自己动手试一试 »

用新窗口替换当前窗口

var myWindow = window.open("", "_self");
myWindow.document.write("<p>我替换了当前窗口。</p>");
自己动手试一试 »

打开一个新窗口并控制其外观

window.open("https://w3schools.org.cn", "_blank", "toolbar=yes,scrollbars=yes,resizable=yes,top=500,left=500,width=400,height=400");
自己动手试一试 »

打开多个选项卡

window.open("http://www.google.com/");
window.open("https://w3schools.org.cn/");
自己动手试一试 »

打开一个新窗口。使用 close() 关闭新窗口

function openWin() {
  myWindow = window.open("", "myWindow", "width=200,height=100");   // 打开一个新窗口
}

function closeWin() {
  myWindow.close();   // 关闭新窗口
}
自己动手试一试 »

打开一个新窗口。使用 name 属性返回新窗口的名称

var myWindow = window.open("", "MsgWindow", "width=200,height=100");
myWindow.document.write("<p>此窗口的名称是: " + myWindow.name + "</p>");
自己动手试一试 »

使用 opener 属性返回创建新窗口的窗口的引用

var myWindow = window.open("", "myWindow", "width=200,height=100");   // 打开一个新窗口
myWindow.document.write("<p>这是 'myWindow'</p>");   // 新窗口中的文本
myWindow.opener.document.write("<p>这是源窗口!</p>");  // 创建新窗口的窗口中的文本
自己动手试一试 »

浏览器支持

open() 在所有浏览器中都受支持

Chrome Edge Firefox Safari Opera IE


×

联系销售

如果您想将 W3Schools 服务用于教育机构、团队或企业,请发送电子邮件给我们
sales@w3schools.com

报告错误

如果您想报告错误,或想提出建议,请发送电子邮件给我们
help@w3schools.com

W3Schools 经过优化,旨在方便学习和培训。示例可能经过简化,以提高阅读和学习体验。教程、参考资料和示例会不断审查,以避免错误,但我们无法保证所有内容的完全正确性。使用 W3Schools 即表示您已阅读并接受我们的使用条款Cookie 和隐私政策

版权所有 1999-2024 Refsnes Data。保留所有权利。W3Schools 由 W3.CSS 提供支持