Window.openDialog() - Web APIs 编辑

Non-standard

This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

window.openDialog() is an extension to window.open(). It behaves the same, except that it can optionally take one or more parameters past windowFeatures, and windowFeatures itself is treated a little differently.

The optional parameters, if present, are bundled up in a JavaScript Array object and added to the newly created window as a property named window.arguments. They may be referenced in the JavaScript of the window at any time, including during the execution of a load handler. These parameters may be used, then, to pass arguments to and from the dialog window.

The call to openDialog() returns immediately. If you want the call to block until the user has closed the dialog, supply modal as a windowFeatures parameter. Note that this also means the user won't be able to interact with the opener window until he closes the modal dialog.

Syntax

newWindow = openDialog(url, name, features, arg1, arg2, ...)
newWindow
The opened window
url
The URL to be loaded in the newly opened window.
name
The window name (optional). See window.open() description for detailed information.
features
See window.open() for details.
arg1, arg2, ...
The arguments to be passed to the new window (optional).

Example

var win = openDialog("http://example.tld/zzz.xul", "dlg", "", "pizza", 6.98);

Notes

New features

all - Initially activates (or deactivates ("all=no")) all chrome (except the behavior flags chrome, dialog and modal). These can be overridden (so "menubar=no,all" turns on all chrome except the menubar.) This feature is explicitly ignored by window.open(). window.openDialog() finds it useful because of its different default assumptions.

Default behavior

The chrome and dialog features are always assumed on, unless explicitly turned off ("chrome=no"). openDialog() treats the absence of the features parameter the same way window.open() does; that is, an empty string sets all features to off) except chrome and dialog, which default to on. If the features parameter is a zero-length string, or contains only one or more of the behavior features (chrome, dependent, dialog and modal) the chrome features are assumed "OS' choice." That is, window creation code is not given specific instructions, but is instead allowed to select the chrome that best fits a dialog on that operating system.

Passing extra parameters to the dialog

To pass extra parameters into the dialog, you can supply them after the windowFeatures parameter:

openDialog("http://example.tld/zzz.xul", "dlg", "", "pizza", 6.98);

The extra parameters will then get packed into a property named arguments of type Array, and this property gets added to the newly opened dialog window.

To access these extra parameters from within dialog code, use the following scheme:

var food  = window.arguments[0];
var price = window.arguments[1];

Note that you can access this property from within anywhere in the dialog code. (Another example).

Returning values from the dialog

Since window.close() erases all properties associated with the dialog window (i.e. the variables specified in the JavaScript code which gets loaded from the dialog), it is not possible to pass return values back past the close operation using globals (or any other constructs).

To be able to pass values back to the caller, you have to supply some object via the extra parameters. You can then access this object from within the dialog code and set properties on it, containing the values you want to return or preserve past the window.close() operation.

var retVals = { address: null, delivery: null };
openDialog("http://example.tld/zzz.xul", "dlg", "modal", "pizza", 6.98,
    retVals);

If you set the properties of the retVals object in the dialog code as described below, you can now access them via the retVals array after the openDialog() call returns.

Inside the dialog code, you can set the properties as follows:

var retVals = window.arguments[2];
retVals.address  = enteredAddress;
retVals.delivery = "immediate";

Specifications

This is not part of any specification.

Browser Compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:93 次

字数:8378

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文