Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

window

这篇翻译不完整。请帮忙从英语翻译这篇文章

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!"
        xmlns="https://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <vbox>
    <hbox>
      <image src="application_form.png"/>
      <description>Register Online!</description>
    </hbox>
    <groupbox align="start">
      <caption label="Your Information"/>
      <radiogroup>
        <vbox>
          <hbox>
            <label control="your-fname" value="Enter first name:"/>
            <textbox id="your-fname" value="Johan"/>
          </hbox>
          <hbox>
            <label control="your-lname" value="Enter last name:"/>
            <textbox id="your-lname" value="Hernandez"/>
          </hbox>
          <hbox>
            <button oncommand="alert('save!')">
              <description>Save</description>
            </button>
          </hbox>
        </vbox>
      </radiogroup>
    </groupbox>
  </vbox>
</window>

标记属性

accelerated
Type: boolean
Set this attribute to true to allow hardware layer managers to accelerate the window.
activetitlebarcolor
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.

 

chromemargin
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.
disablechrome
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.
disablefastfind
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).
drawintitlebar
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.
fullscreenbutton
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.
height
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.
hidechrome
Type: boolean
Set this attribute to true to have the chrome including the titlebar hidden.
id
类型: 元素的ID,在主窗口中必须唯一
一个唯一的标识一边开发者能够定义. 你可以使用方法 getElementById() 或者其他 DOM 的函数并在样式表中添加对元素的引用。

inactivetitlebarcolor
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.
lightweightthemes
Type: boolean
true if the window supports lightweight themes, otherwise false.
lightweightthemesfooter
Type: id
Specifies the ID of an element to which a lightweight theme's footer image will be applied.
screenX
Type: integer
The horizontal position at which the window appears on the screen.
screenY
Type: integer
The vertical position at which the window appears on the screen.
sizemode
Type: one of the values below
The state of the window. It can have one of the following values:
maximized
The window is maximized, and occupies the full size of the screen.
normal
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.

 

title
Type: string
The text to appear in the title bar of the window.
width
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.
windowtype
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: https://mxr.mozilla.org/mozilla-release/search?string=windowtype

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

devtools:scratchpad - Scratchpad windows

navigator:view-source - The view source windows

 

属性

Inherited Properties
align, attributes, allowEvents, baseURI, boxObject, builder, childElementCount, childNodes, children, className, clientHeight, clientLeft, clientTop, clientWidth, collapsed, contextMenu, controllers, database, datasources, dir, firstChild, firstElementChild, flex, height, hidden, id, lastChild, lastElementChild, left, localName, maxHeight, maxWidth, menu, minHeight, minWidth, namespaceURI, nextElementSibling, nextSibling, nodeName, nodeType, nodeValue, observes, ordinal, orient, ownerDocument, pack, parentNode, persist, prefix, previousElementSibling, previousSibling, ref, resource, scrollHeight, scrollLeft, scrollTop, scrollWidth, statusText, style, tagName,textContent, tooltip, tooltipText, top, width

方法

Inherited from XUL element
blur, click, doCommand, focus, getElementsByAttribute

Inherited from DOM element
addEventListener(), appendChild(), dispatchEvent(), getAttribute(), getAttributeNode(), getAttributeNodeNS(), getAttributeNS(), getElementsByTagName(), getElementsByTagNameNS(), hasAttribute(), hasAttributeNS(), hasAttributes(), hasChildNodes(), insertBefore(), isSupported(), normalize(), removeAttribute(), removeAttributeNode(), removeAttributeNS(), removeChild(), removeEventListener(), replaceChild(), setAttribute(), setAttributeNode(), setAttributeNodeNS(), setAttributeNS()

另请参阅: DOM window object methods 

请注意

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

prefwindow, dialog, dialogheader

相关的话题

用户注意事项

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

如果要将小图标添加到地址栏和浏览器选项卡(即对话框不是弹出),请使用下面的代码片段来使用html名称空间和链接。

<window xmlns="https://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
	xmlns:html="https://www.w3.org/1999/xhtml">

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

<!-- From a remote site -->
<html:link rel="icon" href="https://www.mozilla.org/favicon.ico"/>

由于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"/>

or

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

文档标签和贡献者

 此页面的贡献者: Sleepinglight, small-chair
 最后编辑者: Sleepinglight,