--- title: Notification.dir slug: Web/API/notification/dir translation_of: Web/API/Notification/dir ---

{{APIRef("Web Notifications")}}

{{domxref("Notification")}} 的`dir`是一个只读属性,它表示Notification中显示的文本方向 会{{domxref("Notification.Notification","Notification()")}} 构造函数里制定的`dir` 属性的值来设定。

{{AvailableInWorkers}}

语法

var direction = Notification.dir;

一个表示文本方向的{{domxref("DOMString")}}变量。 可能的取值为:

提示:似乎大多数浏览器都忽略了明确的LTR 和RTL 设置,要按照与浏览器的通用设置来操作。

例子

The following snippet fires a notification; a simple options object is created, then the notification is fired using the Notification() constructor.

var options = {
  body: '你去过新疆吗?',
  dir: 'rtl'
}

var n = new Notification('测试通知',options);

n.dir // 应该返回 'rtl'

规则

规则 状态 注释
{{SpecName('Web Notifications','#dom-notification-dir','dir')}} {{Spec2('Web Notifications')}} Living standard

浏览器兼容性

{{ CompatibilityTable() }}

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
基础支持 5 {{ property_prefix("webkit") }} (看提示)
22
{{CompatVersionUnknown}} 4.0 {{ property_prefix("moz") }} (看提示)
22
{{ CompatNo() }} 25 6 (看提示)
Available in workers {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoDesktop("41.0")}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Android Webview Edge Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
基础支持 {{ CompatUnknown() }}

{{CompatVersionUnknown}}

{{CompatVersionUnknown}} 4.0 {{ property_prefix("moz") }} (看注释)
22
1.0.1 {{ property_prefix("moz") }} (看注释)
1.2
{{ CompatNo() }} {{ CompatUnknown() }} {{ CompatNo() }}

{{CompatVersionUnknown}}

能在Worker里调用 {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatGeckoMobile(41.0)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

Firefox OS 提示

{{Page("/en-US/docs/Web/API/Notifications_API", "Firefox OS notes")}}

Chrome 提示

{{Page("/en-US/docs/Web/API/Notifications_API", "Chrome notes")}}

Safari 提示

{{Page("/en-US/docs/Web/API/Notifications_API", "Safari notes")}}

参见