This is an archived page. It's not actively maintained.

window标签用来描述一个窗口的顶级结构,在 XUL文档中,他是一个根节点。默认情况下,它里面的控件是水平排列的。作为一个box容器, box的属性都可以被使用. 默认的, 窗口将有一个特定于平台的框架围绕着他。

如果需要给窗口添加一个图标,你需要首先创建一个 icon 文件,也就是例如 <windowid>.ico<windowid>.xpm ,然后将他们放置到 项目文件夹的/chrome/icons/default/ 目录下. 这里所说的的 <windowid> 是此窗口内window标签的id. 这样,您就能为每个窗口设置不同的图标了。

如果没有将 "chrome://global/skin/"下的指定css文件引用进来, 此窗口将不能正常加载 ,有可能看不见 或者被打开的时候出现漏洞.

注意: 通过Gecko 1.9.2标记, 当一个窗口通过查看动作引起的“激活”或“失活”事件被“激活”或“失活”时,你可以侦测到。这方面的信息,请查看  窗口激活事件.

更多的信息请查看 XUL tutorial.

accelerated, chromemargin, disablechrome, disablefastfind, drawintitlebar, fullscreenbutton, height, hidechrome, id, lightweightthemes, lightweightthemesfooter, screenX, screenY, sizemode, title, width, windowtype


<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<!-- Extremely recommended to keep this css include!! -->
<window id="rootWnd" title="Register Online!"
      <image src="application_form.png"/>
      <description>Register Online!</description>
    <groupbox align="start">
      <caption label="Your Information"/>
            <label control="your-fname" value="Enter first name:"/>
            <textbox id="your-fname" value="Johan"/>
            <label control="your-lname" value="Enter last name:"/>
            <textbox id="your-lname" value="Hernandez"/>
            <button oncommand="alert('save!')">


Type: boolean
Set this attribute to true to allow hardware layer managers to accelerate the window.
Type: color string
Specify background color of the window's titlebar when it is active (foreground). Moreover this hides separator between titlebar and window contents. This only affects Mac OS X.


Type: margin string
Controls the amount of chrome that should be visible on each side of the window. The specified string should contain four numbers, separated by commas, indicating the margin in pixels for the top, right, bottom, and left edges of the window, respectively. This value may be -1 to use the default margin for that side on the current platform, 0 to have no system border (that is, to extend the client area to the edge of the window), or a value greater than zero to indicate how much less than the default default width you wish the margin on that side to be. If this value turns out to be less than 0, 0 is used.
Type: boolean
Set this attribute to true to disable chrome in the window. This is used to hide chrome when showing in-browser UI such as the about:addons page, and causes the toolbars to be hidden, with only the tab strip (and, if currently displayed, the add-on bar) left showing.
Note: This has no effect if the tabs on top preference is turned off.
Type: boolean
Put disablefastfind="true" on the root element of a XUL document, which is intended to be loaded in a tab, to disable the find bar for the tab with this document. This is used to prevent the find bar from being displayed when it's not supported by the content (such as in the Add-ons manager tab).
Type: boolean
If this attribute is true, the top of the window's content area will begin at the top edge of the title bar, instead of below the title bar. This allows the window to draw in the title bar. This is supported only from window elements, and is ignored on platforms that don't support drawing into the title bar.
Type: boolean
Set this attribute to true to display a button in the window chrome to allow the user to switch the window into full screen mode. Supported on Mac OS X 10.7 Lion and later and on Windows. The window receives a "fullscreen" event once the change has been made.
Type: string (representing an integer)
The preferred height of the element in pixels. The actual displayed height may be different if the element or its contents have a minimum or maximum height. The CSS height property may also be used.
Type: boolean
Set this attribute to true to have the chrome including the titlebar hidden.
类型: 元素的ID,在主窗口中必须唯一
一个唯一的标识一边开发者能够定义. 你可以使用方法 getElementById() 或者其他 DOM 的函数并在样式表中添加对元素的引用。

Type: color string
Specify background color of the window's titlebar when it is inactive (background). Moreover this hides separator between titlebar and window contents. This affects only on Mac OS X.
Type: boolean
true if the window supports lightweight themes, otherwise false.
Type: id
Specifies the ID of an element to which a lightweight theme's footer image will be applied.
Type: integer
The horizontal position at which the window appears on the screen.
Type: integer
The vertical position at which the window appears on the screen.
Type: one of the values below
The state of the window. It can have one of the following values:
The window is maximized, and occupies the full size of the screen.
The window appears in a normal state at the desired size.

This attribute is used to save and restore the state of a window (together with the persist attribute) and for CSS styles (e.g. to hide the resizer grippy on maximized windows).

Note: When a window is minimized, the sizemode attribute is not updated. This is done so that if a window is closed while minimized, its persisted sizemode attribute wouldn't be minimized.

Setting this attribute does not change the window state. Use window.maximize(), window.restore(), or window.minimize() to change the window state.

To get the window state from JavaScript code, use window.windowState. Listen to the sizemodechange event dispatched to the DOM window to get notified when the window state changes.

Type: string
The text to appear in the title bar of the window.
Type: string (representing an integer)
The preferred width of the element. The value should not include a unit as all values are in pixels. The actual displayed width may be different if the element or its contents have a minimum or maximum width, or the size is adjusted by the flexibility or alignment of its parent. The CSS width property may also be used.
Type: string
Set to a string which can be used to identify the type of window. This might be used, for example, to distinguish between a browser window and an editor window. Some of Mozilla's window handling functions use this attribute to group windows of the same type together.

Values for window type as found on MXR:

navigator:browser - Looks like if window has gBrowser it has this window type

devtools:scratchpad - Scratchpad windows

navigator:view-source - The view source windows





DTD文件如果丢失或者不可访问,而XUL文件中却引用了其中的内容,将会引起 "XML Parsing Error: undefined entity...<window" 的错误。DOCTYPE声明中系统关键字后如果含有文件名,将会引起没有提示的加载失败, 而唯一的错误提示将会是在下一个XUL元素加载时出现未定义实体的错误。



如果要更改窗口标题栏中的图标, 请参考这里: Window icons.


<window xmlns=""

<!-- Icon from chrome -->
<html:link rel="icon" href="chrome://myExtension/content/path/to/favicon.png"/>

<!-- From a remote site -->
<html:link rel="icon" href=""/>

由于Firefox3.6之前的代码不能正常工作 ——会出现以下提示: "Warning: XUL box for box element contained an inline link child, forcing all its children to be wrapped in a block". 如果这段代码放在window标签之间, 它将会使窗口内的所有其他控件都变得乱七八糟.而如果放在 box 标签之间, 窗口控件呈现反而很不错, 但是依然会引起错误。 这一问题可以如下解决:

<html:link rel="icon" href="chrome://myExtension/content/path/to/favicon.png" style="display:none"/>


  <html:link rel="icon" href="chrome://myExtension/content/path/to/favicon.png"/>