`

window.open

    博客分类:
  • js
阅读更多
window.open(url, name, features, replace)

出自 :  oreilly.javascript.the.definitive.guide.5th.edition.aug.2006


25.309.1.1. Arguments

url

An optional string that specifies the URL to be displayed in the new window. If this argument is omitted, or if the empty string is specified, the new window does not display a document.


name

An optional string of alphanumeric and underscore characters that specifies a name for the new window. This name can be used as the value of the target attribute of <a> and <form> HTML tags. If this argument names a window that already exists, the open( ) method does not create a new window, but simply returns a reference to the named window. In this case, the features argument is ignored.


features

A string that specifies which features of a standard browser window are to appear in the new window. The format of this string is specified in the Window Features section. This argument is optional; if it is not specified, the new window has all the standard features.


replace

An optional boolean argument that specifies whether the URL loaded into the window should create a new entry in the window's browsing history or replace the current entry in the browsing history. If this argument is true, no new history entry is created. Note that this argument is intended for use when changing the contents of an existing named window.

25.309.1.2. Returns

A reference to a Window object, which may be a newly created or an already existing one, depending on the name argument.

25.309.2. Description

The open( ) method looks up an existing window or opens a new browser window. If the name argument specifies the name of an existing window, a reference to that window is returned. The returned window displays the URL specified by url, but the features argument is ignored. This is the only way in JavaScript to obtain a reference to a window that is known only by name.

If the name argument is not specified, or if no window with that name already exists, the open( ) method creates a new browser window. The created window displays the URL specified by url and has the name specified by name and the size and controls specified by features (the format of this argument is described in the next section). If url is the empty string, open( ) opens an empty window.

The name argument specifies a name for the new window. This name may contain only alphanumeric characters and the underscore character. It may be used as the value of the target attribute of an <a> or <form> tag in HTML to force documents to be displayed in the window.

When you use Window.open( ) to load a new document into an existing named window, you can pass the replace argument to specify whether the new document has its own entry in the window's browsing history or whether it replaces the history entry of the current document. If replace is TRue, the new document replaces the old. If this argument is false or is not specified, the new document has its own entry in the Window's browsing history. This argument provides functionality much like that of the Location.replace( ) method.

Don't confuse Window.open( ) with Document.open( ); the two methods perform very different functions. For clarity in your code, you may want to use Window.open( ) instead of open( ). In event handlers defined as HTML attributes, open( ) is usually interpreted as Document.open( ), so in this case, you must use Window.open( ).

25.309.3. Window Features

The features argument is a comma-separated list of features that appears in the window. If this optional argument is empty or not specified, all features are present in the window. On the other hand, if features specifies any one feature, any features that do not appear in the list do not appear in the window. The string should not contain any spaces or other whitespace. Each element in the list has the format:

feature[=value]

 

For most features, the value is yes or no. For these features, the equals sign and the value may be omitted; if the feature appears, yes is assumed, and if it doesn't, no is assumed. For the width and height features, value is required and must specify a size in pixels.

Here are the commonly supported features and their meanings:


height

Specifies the height, in pixels, of the window's document display area.


left

The X coordinate, in pixels, of the window.


location

The input field for entering URLs directly into the browser.


menubar

The menu bar.


resizable

If this feature is not present or is set to no, the window does not have resize handles around its border. (Depending on the platform, the user may still have ways to resize the window.) Note that a common bug is to misspell this feature as "resizeable," with an extra "e."


scrollbars

Enables horizontal and vertical scrollbars when they are necessary.


status

The status line.


toolbar

The browser toolbar, with Back and Forward buttons, etc.


top

The Y coordinate, in pixels, of the window.


width

Specifies the width, in pixels, of the window's document display area.

25.309.4. See Also

Location.replace( ), Window.close( ), the closed and opener properties of Window

分享到:
评论

相关推荐

    JS检测window.open打开的窗口是否关闭

    这可以通过利用`window.open()`方法创建新窗口,并结合`setInterval()`定时器来周期性检查新窗口的状态实现。下面我们将详细讨论如何实现这一功能。 首先,我们使用`window.open()`方法创建一个新的浏览器窗口: `...

    window.open最大化操作

    Window.open最大化操作 在Web开发中,我们经常需要弹出新的浏览器窗口,而在某些情况下,我们需要将这个窗口最大化以便于用户体验。那么,如何使用JavaScript的window.open方法来实现窗口的最大化呢? 首先,让...

    解析window.open的使用方法总结

    `window.open`是JavaScript中的一个内置函数,用于打开新的浏览器窗口或者在已存在的窗口中加载新的内容。这个函数在网页开发中非常常见,特别是在需要创建新窗口或者弹出对话框的场景中。下面将对`window.open`的...

    JS中window.open全屏命令解析及使用示例

    在JavaScript中,`window.open` 是一个非常常用的方法,它用于在浏览器中打开新的窗口或者标签页。这个方法可以接受三个参数:URL、窗口名称和特性字符串,分别用于指定要打开的页面、新窗口的名称以及新窗口的配置...

    window.open()实现post传递参数

    在JavaScript中,`window.open()` 是一个非常常用的函数,用于打开一个新的浏览器窗口或者标签页。通常,`window.open()` 的使用方式是 `window.open(url, target, features)`,其中 `url` 是要打开的页面的地址,`...

    js弹窗返回值详解(window.open方式)

    在讨论JavaScript(简称JS)编程时,一个非常基础且常见的话题是通过window.open方法打开新窗口,并获取从这个新窗口返回的数据。window.open方法是Web开发中的一个标准方法,允许开发者在浏览器窗口中打开新的子...

    javascript 打开页面window.location和window.open的区别.docx

    ### JavaScript打开页面window.location与window.open的区别 #### 一、概述 在JavaScript中,`window.location` 和 `window.open` 都是用来控制浏览器导航的重要API,但它们在使用场景、功能特性和行为上有显著的...

    前端window.open实现激活而非打开的功能

    扩展window.open方法,使得window.open时针对相同的URL地址非打开新窗口,而是仅仅激活已存在窗口,另外,此激活不会刷新页面,不会丢失页面上已存在的数据

    js中window.open打开一个新的页面

    在JavaScript中,`window.open` 是一个非常重要的方法,它用于在浏览器窗口中打开新的、现有的或已命名的窗口。这个方法在网页交互和动态内容加载时尤其常见,比如创建弹窗、打开新链接等。`window.open` 方法的基本...

    window.open()弹出居中的窗口

    ### window.open()弹出居中的窗口 在前端开发过程中,我们常常需要利用JavaScript来实现一些交互功能,其中弹窗操作是非常常见的一种需求。通过`window.open()`方法可以创建一个新的浏览器窗口,而要使得这个新窗口...

Global site tag (gtag.js) - Google Analytics