diff options
Diffstat (limited to 'files/zh-cn/web/api/navigator')
34 files changed, 2818 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/navigator/activevrdisplays/index.html b/files/zh-cn/web/api/navigator/activevrdisplays/index.html new file mode 100644 index 0000000000..6320400e7c --- /dev/null +++ b/files/zh-cn/web/api/navigator/activevrdisplays/index.html @@ -0,0 +1,40 @@ +--- +title: Navigator.activeVRDisplays +slug: Web/API/Navigator/activeVRDisplays +translation_of: Web/API/Navigator/activeVRDisplays +--- +<div>{{DefaultAPISidebar("WebVR API")}}{{SeeCompatTable}}</div> + +<p><strong><code>activeVRDisplays</code></strong>是{{domxref("Navigator")}} 接口返回的数组中每个{{domxref("VRDisplay")}}对象中的的只读属性({{domxref("VRDisplay.ispresenting")}}为<code>true</code>).</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var myActiveDisplays = navigator.activeVRDisplays;</pre> + +<h3 id="返回值">返回值</h3> + +<p>{{domxref("VRDisplay")}}对象数组.</p> + +<h2 id="例子">例子</h2> + +<pre class="brush: js">function showActive() { + var displays = navigator.activeVRDisplays; + for(var i = 0; i < displays.length; i++) { + console.log('Display ' + displays[i].displayId + ' is active.'); + } +} + +</pre> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Navigator.activeVRDisplays")}}</p> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/WebVR_API">WebVR API homepage</a></li> + <li><a href="http://mozvr.com/">MozVr.com</a> — 示例,下载和其他在Mozilla VR团队的资源。</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/battery/index.html b/files/zh-cn/web/api/navigator/battery/index.html new file mode 100644 index 0000000000..b075b170a6 --- /dev/null +++ b/files/zh-cn/web/api/navigator/battery/index.html @@ -0,0 +1,96 @@ +--- +title: Navigator.battery +slug: Web/API/Navigator/battery +translation_of: Web/API/Navigator/battery +--- +<p>{{ ApiRef("Battery API") }}{{deprecated_header}}</p> + +<p><strong>电池状态API</strong>,通常简称为电池API,该API能够让开发者访问用户系统的电池电量以及是否外接电源等电源状态信息,并且在电源状态发生变化时引发事件来开发者。开发者就可以在得知系统电量不足的时候降低你的网站上一些循环执行任务的频率,从而节约电量。或者在电量减少到某个级别的时候,自动保存页面上的一些数据,以防止用户的数据丢失。</p> + +<div class="note"> +<p>电池状态API曾经暴露在{{domxref("window.navigator")}}的<code>battery</code>属性上,但是现在<code>battery</code>属性已经被移除,请使用标准方法{{DOMxRef("Navigator.getBattery","Navigator.getBattery()")}}来代替,该方法返回一个包裹电池状态对象的{{JSxRef("Promise")}}。</p> +</div> + +<h2 id="语法" name="语法">Syntax</h2> + +<pre class="syntaxbox notranslate">var battery = navigator.battery;</pre> + +<h2 id="属性">属性</h2> + +<dl> + <dt><code>charging</code></dt> + <dd><strong>只读</strong>. 一个布尔值,表示了系统电池的充电状态.如果电池正在充电,则返回<code>true</code>,其他情况,比如无法获取系统电池的充电状态,或者系统不使用电池,或者电池不在充电,都返回<code>false</code>.</dd> + <dt><code>chargingTime</code></dt> + <dd><strong>只读</strong>. 一个整字,单位为秒.表示了电池还剩多长时间充满电.如果电池已经充满电了,则返回0.如果电池不在充电,或者无法获取到这个时间值,则返回正无穷大.</dd> + <dt><code>dischargingTime</code></dt> + <dd><strong>只读</strong>.一个数字,单位为秒.表示了电池中的电量还剩多长时间会消耗完毕.如果电池正在充电,或者无法获取到这个时间值,以及如果系统没有电池,则返回正无穷大.</dd> + <dt><code>level</code></dt> + <dd><strong>只读</strong>. 一个数字,单位为秒.表示了系统的电池的电量等级,从0到1.0.如果电量已经完全消耗完,则返回0,如果电量为充满状态,或者无法获取到这个等级值,以及如果系统没有电池,则返回1.0.</dd> +</dl> + +<h2 id="事件">事件</h2> + +<dl> + <dt><code>chargingchange</code></dt> + <dd>当<code>charging</code><code>属性值发生</code>改变时触发该事件.</dd> + <dt><code>chargingtimechange</code></dt> + <dd>当<code>chargingTime属性值发生</code>改变时触发该事件.</dd> + <dt><code>dischargingtimechange</code></dt> + <dd>当<code>dischargingTime</code>属性值发生改变时触发该事件.</dd> + <dt><code>levelchange</code></dt> + <dd>当<code>level属性值发生</code>改变时触发该事件.</dd> +</dl> + +<h2 id="示例">示例</h2> + +<p>查看<a class="external" href="http://dev.w3.org/2009/dap/system-info/battery-status.html#introduction">规范中的这个例子</a>.</p> + +<pre class="brush: js notranslate">var battery = navigator.battery || navigator.mozBattery || navigator.webkitBattery; + +function updateBatteryStatus() { + alert("Battery status: " + battery.level * 100 + " %"); + + if (battery.charging) { + alert("Battery is charging"); + } +} + +battery.addEventListener("chargingchange", updateBatteryStatus); +battery.addEventListener("levelchange", updateBatteryStatus); +updateBatteryStatus(); +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Battery API')}}</td> + <td>{{Spec2('Battery API')}}</td> + <td>Initial specification.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Navigator.battery")}}</p> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>{{DOMxRef("Navigator.getBattery","Navigator.getBattery()")}}</li> + <li><a href="/en-US/docs/Web/API/Battery_Status_API">Battery Status API</a></li> + <li><a class="external" href="http://hacks.mozilla.org/2012/02/using-the-battery-api-part-of-webapi/">Blog post - Using the Battery API</a></li> + <li><a class="external" href="http://davidwalsh.name/battery-api" title="http://davidwalsh.name/battery-api">David Walsh on the JavaScript Battery Api</a></li> + <li><a href="https://github.com/pstadler/battery.js" title="https://github.com/pstadler/battery.js">battery.js - a tiny cross-browser wrapper</a></li> +</ul> diff --git a/files/zh-cn/web/api/navigator/buildid/index.html b/files/zh-cn/web/api/navigator/buildid/index.html new file mode 100644 index 0000000000..8e9d5fa3d0 --- /dev/null +++ b/files/zh-cn/web/api/navigator/buildid/index.html @@ -0,0 +1,39 @@ +--- +title: Navigator.buildID +slug: Web/API/Navigator/buildID +tags: + - API + - DOM + - Gecko + - 属性 +translation_of: Web/API/Navigator/buildID +--- +<p>{{ ApiRef("HTML DOM") }}</p> + +<p>返回所使用浏览器的<span class="short_text" id="result_box" lang="zh-CN"><span class="alt-edited">构建</span><span>标识</span></span>符。现代浏览器中,这个属性返回一个固定的时间戳作为私有的计量方法,比如 Firefox 64 及以后的版本返回 <code>20181001000000</code>。</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="brush: js"><em>buildID</em> = <em>navigator</em>.buildID; +</pre> + +<h3 id="值">值</h3> + +<p>一个字符串,用来表示当前应用的构建标识。构建 ID 的格式为:<code>YYYYMMDDHHMMSS</code>。</p> + +<h2 id="示例"><font face="x-locale-heading-primary, zillaslab, Palatino, Palatino Linotype, x-locale-heading-secondary, serif"><span style="font-size: 37.33327865600586px;"><strong>示例</strong></span></font></h2> + +<pre class="brush: js">console.log(window.navigator.buildID); +</pre> + +<h2 id="Specification" name="Specification">规范</h2> + +<p>未得到任何公共标准支持。</p> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{Compat("api.Navigator.buildID")}}</p> + +<h2 id="另请参阅">另请参阅</h2> + +<p><a href="https://www.fxsitecompat.com/en-CA/docs/2018/navigator-buildid-now-returns-a-fixed-timestamp/">navigator.buildID 现在返回一个固定的时间戳。</a></p> diff --git a/files/zh-cn/web/api/navigator/canshare/index.html b/files/zh-cn/web/api/navigator/canshare/index.html new file mode 100644 index 0000000000..9fe117805d --- /dev/null +++ b/files/zh-cn/web/api/navigator/canshare/index.html @@ -0,0 +1,52 @@ +--- +title: Navigator.canShare +slug: Web/API/Navigator/canShare +translation_of: Web/API/Navigator/canShare +--- +<div>{{APIRef("HTML DOM")}}{{SeeCompatTable}}{{securecontext_header}}</div> + +<div></div> + +<div>如果对<code><a href="https://wiki.developer.mozilla.org/en-US/docs/Web/API/Navigator/share">Navigator.share()</a></code> 的调用成功,则Web Share API的<strong><code>Navigator.canShare()</code></strong>方法将返回true。</div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var canShare = <em>navigator</em>.canShare(<em>data</em>);</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><code>data</code> {{optional_inline}}</dt> + <dd>包含要共享的数据的对象,该对象要与{{domxref("Navigator.share()")}}方法传递的数据相匹配。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>{{jsxref('Boolean')}}值. {{domxref("Navigator.share()")}}若返回True则表示内容可以被成功分享。</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Web Share API 2','#canshare-method','canShare')}}</td> + <td>{{Spec2('Web Share API 2')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Navigator.canShare")}}</p> + +<h2 id="相关连接">相关连接</h2> + +<p>{{domxref('navigator.share', 'navigator.share()')}}</p> diff --git a/files/zh-cn/web/api/navigator/clipboard/index.html b/files/zh-cn/web/api/navigator/clipboard/index.html new file mode 100644 index 0000000000..5c938b9358 --- /dev/null +++ b/files/zh-cn/web/api/navigator/clipboard/index.html @@ -0,0 +1,65 @@ +--- +title: Navigator.clipboard +slug: Web/API/Navigator/clipboard +tags: + - API + - Navigator + - 剪切 + - 剪切板 + - 参考 + - 只读 + - 复制 + - 属性 + - 粘贴 +translation_of: Web/API/Navigator/clipboard +--- +<p><span class="seoSummary">剪贴板 <a href="/zh-CN/docs/Web/API/Clipboard_API">Clipboard API</a> 为 <strong>{{domxref("Navigator")}}</strong> 接口添加了只读属性 <strong><code>clipboard</code></strong>,该属性返回一个可以读写剪切板内容的 {{domxref("Clipboard")}} 对象。</span> 在 Web 应用中,剪切板 API 可用于实现剪切、复制、粘贴的功能。</p> + +<p>只有在用户事先授予网站或应用对剪切板的访问许可之后,才能使用异步剪切板读写方法。许可操作必须通过取得权限 <a href="/zh-CN/docs/Web/API/Permissions_API">Permissions API</a> 的 <code>"clipboard-read"</code> 和/或 <code>"clipboard-write"</code> 项获得。</p> + +<h2 id="语法">语法</h2> + +<pre class="brush: js"><em>theClipboard</em> = navigator.clipboard; +</pre> + +<h3 id="值">值</h3> + +<p>用于访问系统剪切板的 {{domxref("Clipboard")}} 对象。</p> + +<h2 id="示例">示例</h2> + +<p>以下代码使用 <code>navigator.clipboard</code> 来访问系统剪切板,以读取系统剪切板的内容。</p> + +<pre class="brush: js">navigator.clipboard.readText().then( + clipText => document.querySelector(".cliptext").innerText = clipText);;</pre> + +<p>这个代码片段将 HTML 中拥有类名 <code>"cliptext"</code> 的第一个元素的内容替换为剪切板中的内容。这段代码可用于在浏览器拓展中定时自动更新或者由事件触发,实时显示当前剪切板上的内容。</p> + +<p>如果剪切板为空,或者不包含文本,则 <code>"cliptext"</code> 元素的内容将被清空。这是因为在剪切板为空或者不包含文本时,{{domxref("Clipboard.readText", "readText()")}} 会返回一个空字符串。</p> + +<h2 id="标准">标准</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">标准</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Clipboard API','#navigator-clipboard','navigator.clipboard')}}</td> + <td>{{Spec2('Clipboard API')}}</td> + <td>初次定义</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Navigator.clipboard")}}</p> + +<div>{{APIRef("Clipboard API")}}</div> diff --git a/files/zh-cn/web/api/navigator/connection/index.html b/files/zh-cn/web/api/navigator/connection/index.html new file mode 100644 index 0000000000..23e3aaa29b --- /dev/null +++ b/files/zh-cn/web/api/navigator/connection/index.html @@ -0,0 +1,45 @@ +--- +title: Navigator.connection +slug: Web/API/Navigator/connection +translation_of: Web/API/Navigator/connection +--- +<div>{{APIRef("Network Information API")}}{{SeeCompatTable}}</div> + +<p><code><strong>Navigator.connection</strong></code> 是只读的,提供一个{{domxref("NetworkInformation")}} 对象来获取设备的网络连接信息。例如用户设备的当前带宽或连接是否被计量, 这可以用于基于用户的连接来选择高清晰度内容或低清晰度内容。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>connectionInfo</em> = navigator.connection</pre> + +<h3 id="值">值</h3> + +<p>返回网络连接状态NetworkInformation对象,包括.downlink(网络下行速度) effectiveType(网络类型) onchange(有值代表网络状态变更) rtt(估算的往返时间) saveData(打开/请求数据保护模式)</p> + +<h2 id="标准">标准</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">标准</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Network Information', '#h-the-connection-attribute', 'Navigator.connection')}}</td> + <td>{{Spec2('Network Information')}}</td> + <td>初次定义</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容情况">浏览器兼容情况</h2> + +<p>{{Compat("api.Navigator.connection")}}</p> + +<h2 id="参考资料">参考资料</h2> + +<ul> + <li><a href="/en-US/docs/Online_and_offline_events">Online and offline events</a></li> +</ul> diff --git a/files/zh-cn/web/api/navigator/cookieenabled/index.html b/files/zh-cn/web/api/navigator/cookieenabled/index.html new file mode 100644 index 0000000000..033531f4a4 --- /dev/null +++ b/files/zh-cn/web/api/navigator/cookieenabled/index.html @@ -0,0 +1,54 @@ +--- +title: Navigator.cookieEnabled +slug: Web/API/Navigator/cookieEnabled +tags: + - API + - DOM + - cookie + - 属性 +translation_of: Web/API/Navigator/cookieEnabled +--- +<p>{{ ApiRef("HTML DOM") }}</p> + +<p><code>navigator.cookieEnabled</code> 返回一个布尔值,来表示当前页面是否启用了 cookie。本属性为只读属性。</p> + +<h2 id="语法" name="语法">语法</h2> + +<pre class="brush: js">let cookieEnabled = navigator.cookieEnabled; +</pre> + +<ul> + <li><code>cookieEnabled</code> 是个<a href="/zh-CN/docs/Glossary/Boolean">布尔值</a>: <code>true</code> 或 <code>false</code>。</li> +</ul> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">if (!navigator.cookieEnabled) { + // 浏览器不支持 cookie,或者用户禁用了 cookie。 +} +</pre> + +<h2 id="标准">标准</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">标准</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("HTML WHATWG", "webappapis.html#dom-navigator-cookieenabled", "Navigator.cookieEnabled")}}</td> + <td>{{Spec2("HTML WHATWG")}}</td> + <td>初次定义</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Navigator.cookieEnabled")}}</p> diff --git a/files/zh-cn/web/api/navigator/credentials/index.html b/files/zh-cn/web/api/navigator/credentials/index.html new file mode 100644 index 0000000000..c27009d5f1 --- /dev/null +++ b/files/zh-cn/web/api/navigator/credentials/index.html @@ -0,0 +1,101 @@ +--- +title: credentials +slug: Web/API/Navigator/credentials +translation_of: Web/API/Navigator/credentials +--- +<p>{{SeeCompatTable}}{{APIRef("")}}</p> + +<p>{{domxref("Navigator")}}接口的<strong><code>credentials</code></strong>属性返回{{domxref("CredentialsContainer")}}接口,该接口暴露了请求凭证的方法。 {{domxref("CredentialsContainer")}}接口还会在下相关事件发生时通知用户,例如登录或注销成功。该接口可用于特征检测。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var credentialsContainer = navigator.credentials</pre> + +<h3 id="返回值">返回值</h3> + +<p>{{domxref("CredentialsContainer")}} 接口.</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">if ('credentials' in navigator) { + navigator.credentials.get({password: true}) + .then(function(creds) { + //Do something with the credentials. + }); +} else { + //Handle sign-in the way you did before. +}; +</pre> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Credential Management')}}</td> + <td>{{Spec2('Credential Management')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(51.0)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(51.0)}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(51.0)}}</td> + </tr> + </tbody> +</table> +</div> diff --git a/files/zh-cn/web/api/navigator/devicememory/index.html b/files/zh-cn/web/api/navigator/devicememory/index.html new file mode 100644 index 0000000000..b5c5948433 --- /dev/null +++ b/files/zh-cn/web/api/navigator/devicememory/index.html @@ -0,0 +1,41 @@ +--- +title: Navigator.deviceMemory +slug: Web/API/Navigator/deviceMemory +translation_of: Web/API/Navigator/deviceMemory +--- +<p>{{SeeCompatTable}}{{APIRef("Device Memory")}}</p> + +<p><strong><code>deviceMemory</code></strong> 只读属性返回千兆字节为单位的大概的机器内存。这个值是一个2的次方数除以1024,舍去小数点的近似值。并且,上下边界也用来保护那些拥有非常低端或者高端设备的用户的隐私。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox notranslate">const <em>memory</em> = navigator.deviceMemory +console.log ("This device has at least " + memory + "GiB of RAM.") +</pre> + +<h3 id="Value">Value</h3> + +<p>一个浮点类型的数,0.25,0.5,1,2,4,8之一.</p> + +<h2 id="Specifications">Specifications</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Device Memory','#sec-device-memory-js-api','deviceMemory')}}</td> + <td>{{Spec2('Device Memory')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility">Browser compatibility</h2> + +<div class="hidden">此页上的兼容性表是从结构化数据生成的。如果你想对数据有所贡献,请查看https://github.com/mdn/browser-compat-data并向我们发送请求</div> + +<p>{{Compat("api.Navigator.deviceMemory")}}</p> diff --git a/files/zh-cn/web/api/navigator/donottrack/index.html b/files/zh-cn/web/api/navigator/donottrack/index.html new file mode 100644 index 0000000000..5b6535ae97 --- /dev/null +++ b/files/zh-cn/web/api/navigator/donottrack/index.html @@ -0,0 +1,90 @@ +--- +title: Navigator.doNotTrack +slug: Web/API/Navigator/doNotTrack +translation_of: Web/API/Navigator/doNotTrack +--- +<p>{{ ApiRef("HTML DOM") }}{{SeeCompatTable}}</p> + +<h3 id="Summary" name="Summary">概述</h3> + +<p>返回用户的do-not-track设置,如果用户不允许网站,内容和广告等进行跟踪,则该值为yes.</p> + +<h3 id="Syntax" name="Syntax">语法</h3> + +<pre class="eval"><em>dnt</em> = <em>navigator</em>.doNotTrack; +</pre> + +<p><strong><code>navigator.doNotTrack</code></strong>的值并不是 <strong>HTTP请求中do-not-track请求头的值</strong>. 当do-not-track请求头发送的值为"1", <code>navigator.doNotTrack</code> 的值为 "yes". 当do-not-track请求头发送的值为unset, <code>navigator.doNotTrack</code>的值为"unspecified". 当do-not-track请求头发送的值为 "0" (Firefox目前不支持), <code>navigator.doNotTrack</code>的值为"no".</p> + +<h3 id="Example" name="Example">例子</h3> + +<pre class="eval">dump(window.navigator.doNotTrack); +//Firefox中:如果开启了DNT,输出"yes";否则输出"unspecified". +</pre> + +<h3 id="Specification" name="Specification">规范</h3> + +<p><a class="external" href="http://www.w3.org/TR/tracking-dnt/" title="http://www.w3.org/TR/tracking-dnt/">Tracking Preference Expression</a> (工作草案)</p> + +<h3 id="相关链接">相关链接</h3> + +<ul> + <li><a href="/zh-cn/The_Do_Not_Track_Field_Guide" title="https://developer.mozilla.org/zh-cn/The_Do_Not_Track_Field_Guide">The Do Not Track field guide</a></li> +</ul> + +<h3 id="浏览器兼容性">浏览器兼容性</h3> + +<p>{{ CompatibilityTable() }}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{ CompatUnknown() }}</td> + <td>{{ CompatGeckoDesktop("9.0") }}</td> + <td>9</td> + <td>12</td> + <td>5.1 on OS X 10.7</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{ CompatUnknown() }}</td> + <td>{{ CompatGeckoMobile("9.0") }}</td> + <td>{{ CompatUnknown() }}</td> + <td>{{ CompatUnknown() }}</td> + <td>{{ CompatUnknown() }}</td> + </tr> + </tbody> +</table> +</div> + +<ul> + <li>IE9 中该属性带有ms前缀:navigator.msDoNotTrack</li> + <li>IE9, Opera 12和Safari 5.1 实现了早起的旧版本规范:<code>navigator.doNotTrack</code> 的值就是 do-not-track 请求头中的值.</li> +</ul> + +<p>{{ languages( { "en": "en/DOM/navigator.doNotTrack" } ) }}</p> diff --git a/files/zh-cn/web/api/navigator/geolocation/index.html b/files/zh-cn/web/api/navigator/geolocation/index.html new file mode 100644 index 0000000000..89842d99bd --- /dev/null +++ b/files/zh-cn/web/api/navigator/geolocation/index.html @@ -0,0 +1,56 @@ +--- +title: Navigator.geolocation +slug: Web/API/Navigator/geolocation +tags: + - API + - HTTPS + - Navigator + - 参考 + - 地理位置 + - 地理位置 API + - 属性 +translation_of: Web/API/Navigator/geolocation +--- +<p>{{securecontext_header}}{{APIRef("Geolocation API")}}</p> + +<p><strong><code>Navigator.geolocation</code></strong> 只读属性返回一个 {{domxref("Geolocation")}} 对象,通过这个对象可以访问到设备的位置信息。使网站或应用可以根据用户的位置提供个性化结果。</p> + +<div class="note"> +<p><strong>注意:</strong> 出于安全考虑,当网页请求获取用户位置信息时,用户会被提示进行授权。注意不同浏览器在请求权限时有不同的策略和方式。Windows10在未开启定位的情况下无法获取位置</p> +</div> + +<h2 id="语法">语法</h2> + +<pre class="brush: js"><em>geo</em> = <em>navigator</em>.geolocation +</pre> + +<h2 id="标准">标准</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">标准</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Geolocation', '#navi-geo', 'NavigatorGeolocation.geolocation')}}</td> + <td>{{Spec2('Geolocation')}}</td> + <td>初次定义</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{ CompatibilityTable() }}</p> + +<h2 id="另请参阅">另请参阅</h2> + +<ul> + <li><a href="/zh-CN/docs/WebAPI/Using_geolocation">使用地理位置定位</a></li> +</ul> diff --git a/files/zh-cn/web/api/navigator/getbattery/index.html b/files/zh-cn/web/api/navigator/getbattery/index.html new file mode 100644 index 0000000000..29b6b46c0d --- /dev/null +++ b/files/zh-cn/web/api/navigator/getbattery/index.html @@ -0,0 +1,103 @@ +--- +title: Navigator.getBattery() +slug: Web/API/Navigator/getBattery +translation_of: Web/API/Navigator/getBattery +--- +<p>{{ ApiRef("Battery API") }}</p> + +<p><code>getBattery()方法提供了系统的电量信息,返回一个battery的promise对象,然后resolve后得到</code>{{domxref("BatteryManager")}}对象,它提供了一些新的事件,以及方法供您监控电池的状态。这个方法实现了<a href="/en-US/docs/WebAPI/Battery_Status" title="/en-US/docs/WebAPI/Battery_Status">Battery Status API</a> (查看更多细节以及使用方法和实例代码)</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox">navigator.getBattery().then(funcRef);</pre> + +<p><code><em>funcRef</em></code> 是{{domxref("navigator.getBattery")}} 返回的battery promise对象被resolve后执行的函数,即回调函数。</p> + +<h2 id="相关规范">相关规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">阶段</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName("Battery API", "#widl-Navigator-getBattery-Promise-BatteryManager", "Navigator.getBattery")}}</td> + <td>{{Spec2('Battery API')}}</td> + <td>初试定义</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容">浏览器兼容</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>浏览器</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>功能支持</td> + <td>{{CompatChrome(39.0)}}</td> + <td>{{CompatGeckoDesktop("10")}} {{property_prefix("moz")}}<br> + {{CompatGeckoDesktop("16")}}<sup>[1]</sup><br> + {{CompatGeckoDesktop("43")}}<sup>[2]</sup></td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>浏览器</th> + <th>Android</th> + <th>Android Webview</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>功能支持</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(40.0)}}</td> + <td> + <p>{{CompatGeckoMobile("10")}} {{property_prefix("moz")}}<br> + {{CompatGeckoMobile("16")}}<sup>[1]</sup><br> + {{CompatGeckoDesktop("43")}}<sup>[2]</sup></p> + </td> + <td>{{CompatNo}}</td> + <td>25</td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(42.0)}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] 在 Firefox 10.0 被默认禁止, 但可以设置<code>dom.battery.enabled<font face="Open Sans, Arial, sans-serif"> = </font></code><code>true来启用</code>. 从Starting with Firefox 11.0开始, <code>mozBattery</code> 是默认启动的. UPower 安装后, Android, Windows, and Linux.就支持Battery API了。MacOS的支持是从Gecko 18.0 {{geckoRelease("18.0")}}开始的. fireFox依然支持已经被弃用 {{domxref("navigator.battery")}}.</p> + +<p>[2] 全新的基于promise语法的{{domxref("Navigator.getBattery()")}}在FireFox 43 被支持。</p> + +<h2 id="请参见">请参见</h2> + +<ul> + <li><a href="/en-US/docs/WebAPI/Battery_Status" title="/en-US/docs/WebAPI/Battery_Status">Battery Status API</a></li> +</ul> diff --git a/files/zh-cn/web/api/navigator/getgamepads/index.html b/files/zh-cn/web/api/navigator/getgamepads/index.html new file mode 100644 index 0000000000..454b4f4329 --- /dev/null +++ b/files/zh-cn/web/api/navigator/getgamepads/index.html @@ -0,0 +1,107 @@ +--- +title: Navigator.getGamepads() +slug: Web/API/Navigator/getGamepads +translation_of: Web/API/Navigator/getGamepads +--- +<p>{{APIRef("Gamepad API")}}{{SeeCompatTable}}</p> + +<p>调用 <strong><code>Navigator.getGamepads()</code></strong> 方法会返回一个数组:第一个值为 <code>null</code> ,其他的值均为 {{ domxref("Gamepad") }} 对象,表示每一个与设备连接的游戏手柄。所以如果没有连接任何游戏手柄,这个方法将只会返回 <code>null</code>。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"> var arrayGP = navigator.getGamepads();</pre> + +<h2 id="样例">样例</h2> + +<pre class="brush: js">window.addEventListener("gamepadconnected", function(e) { + var gp = navigator.getGamepads()[e.gamepad.index]; + console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.", + gp.index, gp.id, + gp.buttons.length, gp.axes.length); +});</pre> + +<h2 id="标准">标准</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Gamepad', '', 'The Gamepad API specification')}}</td> + <td>{{Spec2('Gamepad')}}</td> + <td>初始定义</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2> + +<p>{{ CompatibilityTable() }}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>General support</td> + <td> + <p>21.0 {{ property_prefix("webkit") }}<br> + 35.0</p> + </td> + <td>{{CompatVersionUnknown}}</td> + <td>{{ CompatGeckoDesktop("29.0") }} [1]</td> + <td>{{ CompatNo() }}</td> + <td> + <p>15.0 {{ property_prefix("webkit") }}<br> + 22.0</p> + </td> + <td>{{ CompatNo() }}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>General support</td> + <td>{{ CompatNo() }}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] 自 Firefox 24 起可以通过偏好设置启用。</p> + +<h2 id="另请参阅">另请参阅</h2> + +<ul> + <li><a href="/en-US/docs/Web/Guide/API/Gamepad">Using the Gamepad API</a></li> + <li><a href="/en-US/docs/Web/API/Gamepad_API">Gamepad API</a></li> +</ul> diff --git a/files/zh-cn/web/api/navigator/getusermedia/index.html b/files/zh-cn/web/api/navigator/getusermedia/index.html new file mode 100644 index 0000000000..11d597fcfc --- /dev/null +++ b/files/zh-cn/web/api/navigator/getusermedia/index.html @@ -0,0 +1,198 @@ +--- +title: navigator.getUserMedia +slug: Web/API/Navigator/getUserMedia +translation_of: Web/API/Navigator/getUserMedia +--- +<div class="note"> +<p><strong>Note:</strong> 此API已更名为 {{domxref("MediaDevices.getUserMedia()")}}。 请使用那个版本进行替代! 这个已废弃的API版本仅为了向后兼容而存在。</p> +</div> + +<p>{{APIRef}}{{deprecated_header}}</p> + +<p><strong>Navigator.getUserMedia()</strong>方法提醒用户需要使用音频(0或者1)和(0或者1)视频输入设备,比如相机,屏幕共享,或者麦克风。如果用户给予许可,<strong>successCallback</strong>回调就会被调用,{{domxref("MediaStream")}}对象作为回调函数的参数。如果用户拒绝许可或者没有媒体可用,<strong>errorCallback</strong>就会被调用,类似的,<strong><code>PermissionDeniedError</code> </strong>或者<strong><code>NotFoundError</code></strong><code>对象作为它的参数。注意,有可能以上两个回调函数都不被调用,因为不要求用户一定作出选择(允许或者拒绝)。</code></p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">navigator.getUserMedia ( constraints, successCallback, errorCallback );</pre> + +<h3 id="参数">参数</h3> + +<p><strong>constraints </strong></p> + +<p>{{domxref("MediaStreamConstaints")}}对象指定了请求使用媒体的类型,还有每个类型的所需要的参数。具体细节请参见{{domxref("MediaDevices.getUserMedia()")}} 方法下面的<a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Parameters">constraints</a>部分。</p> + +<p><strong>successCallback</strong></p> + +<p>当调用成功后,successCallback中指定的函数就被调用,包含了媒体流的{{domxref("MediaStream")}}对象作为它的参数,你可以把媒体流对象赋值给合适的元素,然后使用它,就像下面的例子一样:</p> + +<pre>function(stream) { + var video = document.querySelector('video'); + video.src = window.URL.createObjectURL(stream); + video.onloadedmetadata = function(e) { + // Do something with the video here. + }; +}</pre> + +<dl> +</dl> + +<p><strong>errorCallback</strong></p> + +<p>当调用失败,errorCallback中指定的函数就会被调用,{{domxref("MediaStreamError")}}对象作为它唯一的参数;此对象基于{{domxref("DOMException")}}对象构建。错误码描述见参见以下:</p> + +<table> + <thead> + <tr> + <th scope="col">Error</th> + <th scope="col">Description</th> + </tr> + </thead> + <tbody> + <tr> + <td><code>PermissionDeniedError</code></td> + <td>使用媒体设备请求被用户或者系统拒绝</td> + </tr> + <tr> + <td><code>NotFoundError</code></td> + <td> + <p>找不到constraints中指定媒体类型</p> + </td> + </tr> + </tbody> +</table> + +<h2 id="示例">示例</h2> + +<h3 id="宽度和高度">宽度和高度</h3> + +<p>使用getUserMedia()的示例,包括了可以适用于多种浏览器前缀的代码。注意这种使用方式已经被废除,现代的使用方法请参见{{domxref("MediaDevices.getUserMedia()")}} 下面的<a href="https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia#Frame_rate">示例</a>部分。</p> + +<pre><code>navigator.getUserMedia = navigator.getUserMedia || + navigator.webkitGetUserMedia || + navigator.mozGetUserMedia; + +if (navigator.getUserMedia) { + navigator.getUserMedia({ audio: true, video: { width: 1280, height: 720 } }, + function(stream) { + var video = document.querySelector('video'); + video.src = window.URL.createObjectURL(stream); + video.onloadedmetadata = function(e) { + video.play(); + }; + }, + function(err) { + console.log("The following error occurred: " + err.name); + } + ); +} else { + console.log("getUserMedia not supported"); +}</code></pre> + +<h2 id="权限">权限</h2> + +<p>在一个可以安装的app(比如,Firefox OS app)中使用getUserMedia(),你需要在你的manifest文件中指定一个或者多个以下条目:</p> + +<pre><code>"permissions": { + "audio-capture": { + "description": "Required to capture audio using getUserMedia()" + }, + "video-capture": { + "description": "Required to capture video using getUserMedia()" + } +}</code></pre> + +<p>参见 <a href="https://developer.mozilla.org/en-US/Apps/Developing/App_permissions#audio-capture">permission: audio-capture</a> 和 <a href="https://developer.mozilla.org/en-US/Apps/Developing/App_permissions#video-capture">permission: video-capture</a> 以查看更多信息。</p> + +<h2 id="规格">规格</h2> + +<table> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Media Capture', '#navigatorusermedia-interface-extensions', 'navigator.getUserMedia')}}</td> + <td>{{Spec2('Media Capture')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div class="warning"> +<p>新代码应当使用 {{domxref("Navigator.mediaDevices.getUserMedia()")}} 替代.</p> +</div> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>21{{property_prefix("webkit")}} [1]</td> + <td>17{{property_prefix("moz")}} [3]</td> + <td>{{CompatNo}}</td> + <td>12 [2]<br> + 18{{property_prefix("webkit")}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> +<div id="compat-mobile"> +<table> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic Support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome(40.0)}}{{property_prefix("webkit")}} [2]</td> + <td>24{{property_prefix("moz")}} [3]</td> + <td>1.2{{property_prefix("moz")}} [4]<br> + 1.4{{property_prefix("moz")}}</td> + <td>{{CompatNo}}</td> + <td>12 [2]</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> +<p>[1] 新版的Chrome支持未带前缀的 {{domxref("MediaDevices.getUserMedia()")}}, 用以取代此已废弃版本.</p> + +<p>[2] Chrome 和 Opera 仍然在使用已经过期的 constraint 语法, 但是此描述中的语法可以通过 <a href="https://github.com/webrtc/adapter">adapter.js</a> polyfill来使用.</p> + +<p>[3] 在此描述的constraint 语法自 Firefox 38后可用. 更早的版本 (32-37) 使用了已经过期的语法, 但是此描述中的语法可以通过 <a href="https://github.com/webrtc/adapter">adapter.js</a> polyfill来使用.</p> + +<p>[4] 在 Firefox OS 1.2中, 只有音频的到支持, 1.4 添加了视频支持.</p> + +<h2 id="更多参见">更多参见 </h2> + +<ul> + <li>{{domxref("MediaDevices.getUserMedia()")}} 替代了当前废弃的版本。</li> + <li><a href="https://developer.mozilla.org/en-US/docs/WebRTC">WebRTC</a> - the introductory page to the API</li> + <li><a href="https://developer.mozilla.org/en-US/docs/WebRTC/MediaStream_API">MediaStream API</a> - the API for the media stream objects</li> + <li><a href="https://developer.mozilla.org/en-US/docs/WebRTC/taking_webcam_photos">Taking webcam photos</a> - a tutorial on using <code>getUserMedia() for taking photos rather than video.</code></li> +</ul> diff --git a/files/zh-cn/web/api/navigator/id/index.html b/files/zh-cn/web/api/navigator/id/index.html new file mode 100644 index 0000000000..c2d8597274 --- /dev/null +++ b/files/zh-cn/web/api/navigator/id/index.html @@ -0,0 +1,45 @@ +--- +title: Navigator.id +slug: Web/API/Navigator/id +translation_of: Archive/Navigator-id +--- +<div>{{ ApiRef("Persona") }}</div> + +<p>{{ non-standard_header() }}</p> + +<div class="note"><strong>注意:</strong> 这个功能的支持还没有构建到任何浏览器中,使用 Persona 的网站必须包含托管在 <a class="link-https" href="https://login.persona.org/include.js" title="https://login.persona.org/include.js">https://login.persona.org/include.js</a> 上的填充库。</div> + +<h2 id="Summary" name="Summary">概述</h2> + +<p><a href="https://developer.mozilla.org/en-US/docs/Persona" title="BrowserID">BrowserID 协议</a>定义了 {{ domxref ("window.navigator")}} 对象上的一个新的 <code>id</code> 属性,通过这个属性暴露 BrowserID API。这个 API 已经经历了几个重要修订。下面独立列出了每代 API。</p> + +<h2 id="ObserverMethods" name="ObserverMethods">观察者 API(当前)</h2> + +<p>观察者 API 引入了非常请求化的特性,诸如一个为新手用户改进的提交-验证体验、自动持久化登入和更简单的本地应用集成。</p> + +<dl> + <dt>{{ domxref("navigator.id.watch()")}}</dt> + <dd>登记在用户登入或登出网站时调用的回调。</dd> + <dt>{{ domxref("navigator.id.request()")}}</dt> + <dd>从用户请求一个签名的身份断言。</dd> + <dt>{{ domxref("navigator.id.logout()")}}</dt> + <dd>把用户登出网站并阻止 <code>onlogin</code> 行为在他们下次访问时触发。</dd> +</dl> + +<h2 id="CallbackMethods" name="CallbackMethods">回调 API(当前)</h2> + +<p>回调 API 在 2011 年 11 月被引入。它通过允许传递给 <code>navigator.id.get()</code>和提供 BrowserID 管理的持久会话的实验性支持改进了初始的 API。</p> + +<dl> + <dt>{{ domxref("navigator.id.get()")}}</dt> + <dd>Gets the user's BrowserID in a signed assertion.</dd> +</dl> + +<h2 id="VerifiedEmailMethods" name="VerifiedEmailMethods">VerifiedEmail API(弃用)</h2> + +<p>VerifiedEmail API 是 BrowserID 的第一个 API。它在 2011 年末被弃用。</p> + +<dl> + <dt>{{ domxref("navigator.id.getVerifiedEmail()")}} {{ deprecated_inline() }}</dt> + <dd>在一个签名的断言里获取用户的 BrowserID。这个方法已经弃用了;{{ domxref("navigator.id.get()")}} 是向后兼容的替代方法。</dd> +</dl> diff --git a/files/zh-cn/web/api/navigator/index.html b/files/zh-cn/web/api/navigator/index.html new file mode 100644 index 0000000000..a68d752556 --- /dev/null +++ b/files/zh-cn/web/api/navigator/index.html @@ -0,0 +1,172 @@ +--- +title: Navigator +slug: Web/API/Navigator +tags: + - API + - DOM4 + - Navigator + - 接口 +translation_of: Web/API/Navigator +--- +<p>{{apiref("DOM4")}}</p> + +<p><code>Navigator</code> 接口表示用户代理的状态和标识。 它允许脚本查询它和注册自己进行一些活动。</p> + +<p>可以使用只读的 {{domxref("window.navigator")}} 属性检索navigator对象。</p> + +<h2 id="属性">属性</h2> + +<p>不从<em>{{domxref("NavigatorID")}}, {{domxref("NavigatorLanguage")}}, {{domxref("NavigatorOnLine")}}, {{domxref("NavigatorGeolocation")}}, {{domxref("NavigatorPlugins")}}, {{domxref("NavigatorUserMedia")}}, </em>和 <em>{{domxref("NetworkInformation")}} </em>中继承任何属性,但是实现了定义在这些对象中的如下属性。</p> + +<h3 id="标准属性">标准属性</h3> + +<dl> + <dt>{{domxref("Navigator.activeVRDisplays")}} {{readonlyInline}}{{experimental_inline}}</dt> + <dd>筛选所有的 {{domxref("VRDisplay")}} 对象,把其中所有{{domxref("VRDisplay.ispresenting")}}属性的值为<code>true</code>的对象以数组的形式返回。 </dd> + <dt>{{domxref("NavigatorID.appCodeName")}} {{readonlyInline}}{{deprecated_inline}}</dt> + <dd>返回当前浏览器的内部“开发代号”名称。 不能保证此属性返回的值是正确的。</dd> + <dt>{{domxref("NavigatorID.appName")}} {{readonlyInline}}{{deprecated_inline}}</dt> + <dd>以 {{domxref("DOMString")}} 的形式返回浏览器官方名称。 不能保证此属性返回的值是正确的。</dd> + <dt>{{domxref("NavigatorID.appVersion")}} {{readonlyInline}}{{deprecated_inline}}</dt> + <dd>以 {{domxref("DOMString")}} 的形式返回浏览器版本。不能保证此属性返回的值是正确的。</dd> + <dt>{{domxref("Navigator.battery")}} {{readonlyInline}}{{deprecated_inline}}</dt> + <dd>返回一个 {{domxref("BatteryManager")}} 对象,你可以用它来获取一些电池充电状态的信息。</dd> + <dt>{{domxref("Navigator.connection")}} {{readonlyInline}}{{experimental_inline}}</dt> + <dd>提供一个{{domxref("NetworkInformation")}}对象来获取设备的网络连接信息。</dd> + <dt>{{domxref("Navigator.cookieEnabled")}} {{readonlyinline}}</dt> + <dd>当忽略 cookie 时返回 false,否则返回 true</dd> + <dt>{{domxref("Navigator.geolocation")}} {{readonlyInline}}</dt> + <dd>返回一个 {{domxref("Geolocation")}} 对象,据之可访问设备的地理位位置信息。</dd> + <dt>{{domxref("NavigatorConcurrentHardware.hardwareConcurrency")}} {{readOnlyInline}}</dt> + <dd>返回可用的逻辑处理器核心数。</dd> + <dt>{{domxref("NavigatorPlugins.javaEnabled")}} {{readonlyInline}}{{experimental_inline}}</dt> + <dd>返回{{domxref("Boolean")}}表明浏览器是否支持Java。</dd> + <dt>{{domxref('Navigator.keyboard')}} {{readonlyinline}} {{experimental_inline}}</dt> + <dd>返回一个{{domxref("Keyboard")}}对象,该对象提供对以下功能的访问:检索键盘布局图和切换从物理键盘捕获按键的功能。</dd> + <dt>{{domxref("NavigatorLanguage.language")}} {{readonlyInline}}</dt> + <dd>返回{{domxref("DOMString")}}表示用户的首先语言,通常是浏览器用户界面的语言。当未知的时,返回null。</dd> + <dt>{{domxref("NavigatorLanguage.languages")}} {{readonlyInline}}</dt> + <dd> 返回一个表示用户已知语言的{{domxref("DOMString")}}数组,并按优先顺序排列。</dd> + <dt>{{domxref("NavigatorPlugins.mimeTypes")}} {{readonlyInline}}{{experimental_inline}}</dt> + <dt>{{domxref("Navigator.locks")}} {{readonlyinline}}{{experimental_inline}}</dt> + <dd>Returns a {{domxref("LockManager")}} object which provides methods for requesting a new {{domxref('Lock')}} object and querying for an existing {{domxref('Lock')}} object</dd> + <dt>{{domxref("Navigator.mediaCapabilities")}} {{readonlyinline}}{{experimental_inline}}</dt> + <dd>Returns a {{domxref("MediaCapabilities")}} object that can expose information about the decoding and encoding capabilities for a given format and output capabilities.</dd> + <dt>{{domxref("Navigator.maxTouchPoints")}} {{readonlyInline}}</dt> + <dd>Returns the maximum number of simultaneous touch contact points are supported by the current device.</dd> + <dd>返回{{domxref("MimeTypeArray")}}数组用于列举浏览器所支持的MIME类型。</dd> + <dt>{{domxref("NavigatorOnLine.onLine")}} {{readonlyInline}}</dt> + <dd>返回{{domxref("Boolean")}}来表明浏览器是否联网。</dd> + <dt>{{domxref("Navigator.oscpu")}}</dt> + <dd>返回当前操作系统名。</dd> + <dt>{{domxref("Navigator.permissions")}} {{readonlyinline}}{{experimental_inline}}</dt> + <dd>返回一个{{domxref("Permissions")}}对象,该对象可用于查询和更新<a href="/en-US/docs/Web/API/Permissions_API">Permissions API</a>涵盖的API的权限状态。</dd> + <dt>{{domxref("NavigatorID.platform")}} {{readonlyInline}}{{experimental_inline}}</dt> + <dd>返回浏览器平台名,不确定此值是否有效。</dd> + <dt>{{domxref("NavigatorPlugins.plugins")}} {{readonlyInline}}{{experimental_inline}}</dt> + <dd>返回{{domxref("PluginArray")}}数组用于列举出浏览器安装的插件。</dd> + <dt>{{domxref("NavigatorID.product")}} {{readonlyInline}} {{experimental_inline}}</dt> + <dd>在任意浏览器下都只返回<code>'Gecko'</code>,此属性只用于兼容的目的。</dd> + <dt>{{domxref("Navigator.serviceWorker")}} {{readonlyInline}}</dt> + <dd>返回{{domxref("ServiceWorkerContainer")}} 对象用于提供注册、删除、更新以及为了<a href="https://html.spec.whatwg.org/multipage/browsers.html#concept-document-window">associated document</a>的{{domxref("ServiceWorker")}}对象之间的通信。</dd> + <dt>{{domxref("NavigatorStorage.storage")}} {{readonlyinline}}</dt> + <dd>Returns the singleton {{domxref('StorageManager')}} object used for managing persistence permissions and estimating available storage on a site-by-site/app-by-app basis.</dd> + <dt>{{domxref("NavigatorID.userAgent")}} {{readonlyInline}}</dt> + <dd>返回当前浏览器的用户代理。</dd> + <dt>{{domxref("Navigator.webdriver")}} {{readonlyInline}} {{experimental_inline}}</dt> +</dl> + +<h3 id="Methods" name="Methods">非标准方法</h3> + +<dl> + <dt>{{domxref("window.navigator.buildID", "navigator.buildID")}} {{non-standard_inline}}</dt> + <dd>返回浏览器识别码。这一方法返回时间戳,例如,在Firefox 64发行版中返回"<code>20181001000000</code>"。.</dd> + <dt>{{domxref("Navigator.cookieEnabled")}} {{non-standard_inline}}</dt> + <dd>返回布尔值以表明cookies是否能再浏览器中启用</dd> + <dt>{{domxref("navigator.doNotTrack")}} {{non-standard_inline}}</dt> + <dd>报告用户的不追踪参数值,当值为yes,你的网址或应用将不追踪用户</dd> + <dt>{{domxref("navigator.id")}} {{non-standard_inline}}</dt> + <dd>返回 {{domxref("window.navigator.id", "id")}} 对象, 你能用 <a href="/en-US/docs/BrowserID" title="BrowserID">BrowserID</a> 添加支持 到你的网址</dd> + <dt>{{domxref("window.navigator.mozApps", "navigator.mozApps")}} {{non-standard_inline}}</dt> + <dd>Returns an {{domxref("window.navigator.mozApps", "Apps")}} object you can use to install, manage, and control <a href="/Open_Web_Apps" title="Open Web apps">Open Web apps</a>.</dd> + <dt>{{domxref("Navigator.mozAudioChannelManager", "navigator.mozAudioChannelManager")}} {{non-standard_inline}}</dt> + <dd>The <code>navigator.mozAudioChannelManager</code> object provides access to the {{domxref("mozAudioChannelManager")}} interface, which is used to manage your Firefox OS device's audio channels, including setting what channel's volume to affect when the volume buttons are pressed inside a particular app.</dd> + <dt>{{domxref("window.navigator.mozNotification","navigator.mozNotification")}} {{deprecated_inline("22")}} {{non-standard_inline}}<br> + {{domxref("window.navigator.webkitNotification","navigator.webkitNotification")}}</dt> + <dd>Returns a {{domxref("navigator.mozNotification", "notification")}} object you can use to deliver notifications to the user from your web application.</dd> + <dt>{{domxref("navigator.mozSocial")}} {{non-standard_inline}}</dt> + <dd>The Object, returned by the <code>navigator.mozSocial</code> property, is available within the social media provider's panel to provide functionality it may need.</dd> + <dt>{{domxref("window.navigator.productSub", "navigator.productSub")}} {{non-standard_inline}}</dt> + <dd>Returns the build number of the current browser (e.g., "20060909").</dd> + <dt>{{domxref("window.navigator.securitypolicy", "navigator.securitypolicy")}} {{non-standard_inline}}</dt> + <dd>Returns an empty string. In Netscape 4.7x, returns "US & CA domestic policy" or "Export policy".</dd> + <dt>{{domxref("window.navigator.standalone", "navigator.standalone")}} {{non-standard_inline}}</dt> + <dd>Returns a boolean indicating whether the browser is running in standalone mode. Available on Apple's iOS Safari only.</dd> + <dt>{{domxref("window.navigator.vendor", "navigator.vendor")}} {{non-standard_inline}}</dt> + <dd>返回当前浏览器的供应商的名字(例如:“Netscape6”)。</dd> + <dt>{{domxref("window.navigator.vendorSub", "navigator.vendorSub")}} {{non-standard_inline}}</dt> + <dd>返回供应商版本号码(例如:“6.1”)。</dd> + <dt><a href="/en-US/docs/API/Pointer_Lock_API" title="Mouse Lock API"><code>navigator.webkitPointer</code></a> {{non-standard_inline}}</dt> + <dd>Returns a PointerLock object for the <a href="/en-US/docs/API/Pointer_Lock_API" title="Mouse Lock API">Mouse Lock API</a>.</dd> +</dl> + +<h2 id="Methods" name="Methods">方法</h2> + +<p><em>Doesn't inherit any method, but implements those defined in {{domxref("NavigatorID")}}, {{domxref("NavigatorContentUtils")}}, <em>{{domxref("NavigatorUserMedia")}}, </em>and {{domxref("NavigatorStorageUtils")}}.</em></p> + +<h3 id="标准方法">标准方法</h3> + +<dl> + <dt>{{domxref("Navigator.getVRDisplays()")}} {{deprecated_inline}}</dt> + <dd>Returns a promise that resolves to an array of {{domxref("VRDisplay")}} objects representing any available VR devices connected to the computer.</dd> + <dt>{{domxref("NavigatorUserMedia.getUserMedia()")}}{{deprecated_inline}}</dt> + <dd>After having prompted the user for permission, returns the audio or video stream associated to a camera or microphone on the local computer.</dd> + <dt>{{domxref("window.navigator.registerContentHandler", "navigator.registerContentHandler")}}</dt> + <dd>Allows web sites to register themselves as a possible handler for a given MIME type.</dd> + <dt>{{domxref("navigator.registerProtocolHandler", "navigator.registerProtocolHandler")}}</dt> + <dd>Allows web sites to register themselves as a possible handler for a given protocol.</dd> + <dt>{{domxref("Navigator.requestMediaKeySystemAccess()")}} {{experimental_inline}}</dt> + <dd>Returns a {{jsxref("Promise")}} for a MediaKeySystemAccess object.</dd> + <dt>{{domxref("Navigator.sendBeacon()")}}{{experimental_inline}}</dt> + <dd>Used to asynchronously transfer a small amount of data using {{Glossary("HTTP")}} from the User Agent to a web server.</dd> + <dt>{{domxref("Navigator.share()")}}{{experimental_inline}}</dt> + <dd>Invokes the native sharing mechanism of the current platform.</dd> + <dt>{{domxref("NavigatorID.taintEnabled()")}} {{deprecated_inline("1.7.8")}} {{obsolete_inline("9.0")}} {{experimental_inline}}</dt> + <dd>Returns <code>false</code>. JavaScript taint/untaint functions removed in JavaScript 1.2.</dd> + <dt>{{domxref("Navigator.vibrate()")}} {{gecko_minversion_inline("11.0")}}</dt> + <dd>Causes vibration on devices with support for it. Does nothing if vibration support isn't available.</dd> +</dl> + +<h3 id="Specification" name="Specification">非标准方法</h3> + +<dl> + <dt>{{domxref("window.navigator.mozIsLocallyAvailable", "navigator.mozIsLocallyAvailable")}} {{non-standard_inline}}</dt> + <dd>Lets code check to see if the document at a given URI is available without using the network.</dd> + <dt>{{domxref("window.navigator.mozPay", "navigator.mozPay")}} {{non-standard_inline}}</dt> + <dd>Allows in-app payment.</dd> +</dl> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#the-navigator-object', 'the Navigator object')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div class="hidden">The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out <a class="external" href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</div> + +<div>{{Compat("api.Navigator")}}</div> diff --git a/files/zh-cn/web/api/navigator/keyboard/index.html b/files/zh-cn/web/api/navigator/keyboard/index.html new file mode 100644 index 0000000000..1db37aaa2f --- /dev/null +++ b/files/zh-cn/web/api/navigator/keyboard/index.html @@ -0,0 +1,41 @@ +--- +title: Navigator.keyboard +slug: Web/API/Navigator/keyboard +translation_of: Web/API/Navigator/keyboard +--- +<div>{{SeeCompatTable}}{{APIRef("Keyboard API")}}</div> + +<p><span class="seoSummary">The <strong><code>keyboard</code></strong> read-only property of the {{domxref("navigator")}} interface returns a {{domxref('Keyboard')}} object which provides access to functions that retrieve keyboard layout maps and toggle capturing of key presses from the physical keyboard. </span></p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var <var>keyboard</var> = navigator.keyboard</pre> + +<h3 id="Value">Value</h3> + +<p>一个 {{domxref('Keyboard')}} 对象.</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Keyboard Map','#navigator-interface','keyboard')}}</td> + <td>{{Spec2('Keyboard Map')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.navigator.keyboard")}}</p> diff --git a/files/zh-cn/web/api/navigator/maxtouchpoints/index.html b/files/zh-cn/web/api/navigator/maxtouchpoints/index.html new file mode 100644 index 0000000000..49e0d303ba --- /dev/null +++ b/files/zh-cn/web/api/navigator/maxtouchpoints/index.html @@ -0,0 +1,100 @@ +--- +title: Navigator.maxTouchPoints +slug: Web/API/Navigator/maxTouchPoints +translation_of: Web/API/Navigator/maxTouchPoints +--- +<div>{{apiref("HTML DOM")}}</div> + +<div>返回当前设备能够支持的最大同时触摸的点数。</div> + +<div> </div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>touchPoints</em> = <em>navigator</em>.maxTouchPoints; +</pre> + +<h2 id="样例">样例</h2> + +<pre class="brush: js">if (navigator.maxTouchPoints > 1) { + // 浏览器支持多点触控 +} +</pre> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Pointer Events 2','#extensions-to-the-navigator-interface', 'maxTouchPoints')}}</td> + <td>{{Spec2('Pointer Events 2')}}</td> + <td>Non-stable version.</td> + </tr> + <tr> + <td>{{SpecName('Pointer Events', '#extensions-to-the-navigator-interface', 'maxTouchPoints')}}</td> + <td>{{Spec2('Pointer Events')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{CompatibilityTable}}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome("35")}}<sup>[1]</sup></td> + <td>{{CompatGeckoDesktop("29")}}<sup>[2]</sup></td> + <td>10 {{property_prefix("-ms")}}<br> + 11</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatChrome("35")}}<sup>[1]</sup></td> + <td>{{CompatGeckoMobile("29")}}<sup>[2]</sup></td> + <td>10 {{property_prefix("-ms")}}<br> + 11</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] This was implemented in <a href="http://crbug.com/248918">bug 248918</a>.</p> + +<p>[2] Gecko supports this feature behind the preference <code>dom.w3c_pointer_events.enabled</code>, defaulting to <code>false</code>.</p> diff --git a/files/zh-cn/web/api/navigator/mediadevices/index.html b/files/zh-cn/web/api/navigator/mediadevices/index.html new file mode 100644 index 0000000000..f8df63585c --- /dev/null +++ b/files/zh-cn/web/api/navigator/mediadevices/index.html @@ -0,0 +1,115 @@ +--- +title: Navigator.mediaDevices +slug: Web/API/Navigator/mediaDevices +tags: + - Media + - Media Capture and Streams API + - Media Streams API + - MediaDevices + - Navigator + - Reference + - Web + - 只读 + - 属性 +translation_of: Web/API/Navigator/mediaDevices +--- +<div>{{APIRef("Media Capture and Streams")}}</div> + +<div> </div> + +<div>mediaDevices 是 Navigator 只读属性,返回一个 {{domxref("MediaDevices")}} 对象,该对象可提供对相机和麦克风等媒体输入设备的连接访问,也包括屏幕共享。</div> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var <em>mediaDevices</em> = navigator.mediaDevices; +</pre> + +<h3 id="返回值"> 返回值</h3> + +<p>{{domxref("MediaDevices")}} 是一个单例对象。通常,您只需直接使用此对象的成员,例如通过调用{{domxref("navigator.mediaDevices.getUserMedia()")}}。</p> + +<h2 id="特性">特性</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Media Capture', '#widl-NavigatorUserMedia-mediaDevices', 'NavigatorUserMedia.mediaDevices')}}</td> + <td>{{Spec2('Media Capture')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容">浏览器兼容</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Edge</th> + <th>Firefox (Gecko)</th> + <th>Microsoft Edge</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(51.0)}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoDesktop("36.0")}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Edge</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}</td> + <td>{{CompatGeckoMobile("36.0")}}</td> + <td>{{CompatGeckoMobile("36.0")}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="参考阅读">参考阅读</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Media_Streams_API">Media Capture and Streams API</a>: The entry point to the documentation about the entire media stream API.</li> + <li><a href="/en-US/docs/Web/API/WebRTC_API">WebRTC API</a>: Documentation about the WebRTC API, which is closely related.</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/mozislocallyavailable/index.html b/files/zh-cn/web/api/navigator/mozislocallyavailable/index.html new file mode 100644 index 0000000000..19bccd5ef2 --- /dev/null +++ b/files/zh-cn/web/api/navigator/mozislocallyavailable/index.html @@ -0,0 +1,42 @@ +--- +title: Navigator.mozIsLocallyAvailable() +slug: Web/API/Navigator/mozIsLocallyAvailable +translation_of: Web/API/Navigator/mozIsLocallyAvailable +--- +<p>{{APIRef("HTML DOM")}}{{Non-standard_header}}</p> + +<h3 id="Summary" name="Summary">概述</h3> + +<p>查询某个URI上的资源是否是本地可用的.</p> + +<h3 id="Syntax" name="Syntax">语法</h3> + +<pre class="eval">window.navigator.mozIsLocallyAvailable(<em>uri</em>, <em>ifOffline</em>); +</pre> + +<ul> + <li><code>uri</code> 将要查询本地可用性的的资源的URI.</li> + <li><code>ifOffline</code> 是否检查离线资源缓存<code>.</code></li> +</ul> + +<h3 id="Example" name="Example">例子</h3> + +<pre class="eval">var available = navigator.mozIsLocallyAvailable("http:www.example.com/my-image-file.png", true); +if (available) { + /* 该离线资源可用 */ +} else { + alert("离线资源不可用,必须联网."); +} +</pre> + +<h3 id="Notes" name="Notes">备注</h3> + +<p>{{ Note("查询的URI和当前页面的URI不同域的话,会抛出安全异常.") }}</p> + +<h3 id="Specification" name="Specification">规范</h3> + +<p>无规范; 这里有一些可用信息: <a class="external" href="http://www.campd.org/stuff/Offline%20Cache.html">将资源标记为离线可用</a>.</p> + +<p> </p> + +<p>{{ languages( { "fr": "fr/DOM/window.navigator.isLocallyAvailable", "en": "en/DOM/window.navigator.isLocallyAvailable", "ja": "ja/DOM/window.navigator.mozIsLocallyAvailable" } ) }}</p> diff --git a/files/zh-cn/web/api/navigator/mozsettings/index.html b/files/zh-cn/web/api/navigator/mozsettings/index.html new file mode 100644 index 0000000000..bd96466118 --- /dev/null +++ b/files/zh-cn/web/api/navigator/mozsettings/index.html @@ -0,0 +1,32 @@ +--- +title: Navigator.mozSettings +slug: Web/API/Navigator/mozSettings +translation_of: Archive/B2G_OS/API/Navigator/mozSettings +--- +<p>{{APIRef("Firefox OS")}}{{ non-standard_header() }}</p> + +<p>{{ B2GOnlyHeader2('certified') }}</p> + +<h2 id="Summary" name="Summary">概述</h2> + +<p>返回一个{{ domxref("SettingsManager") }}对象,你可以使用返回的对象来修改设备的各项设置.</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="eval">var settings = window.navigator.mozSettings; +</pre> + +<h2 id="Value" name="Value">值</h2> + +<p><code>navigator.mozSettings</code>是一个{{domxref("SettingsManager")}}对象,你可以使用该对象来修改设备的各项设置.</p> + +<h2 id="Specification" name="Specification">规范</h2> + +<p>目前还不属于任何的规范,不过这个API将作为<a class="external" href="http://www.w3.org/2012/sysapps/" rel="external" title="http://www.w3.org/2012/sysapps/">System Applications Working Group</a>规范的一部分在W3C上讨论.</p> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>{{domxref("SettingsManager")}}</li> + <li>{{domxref("SettingsLock")}}</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/mozsms/index.html b/files/zh-cn/web/api/navigator/mozsms/index.html new file mode 100644 index 0000000000..c6c9aff864 --- /dev/null +++ b/files/zh-cn/web/api/navigator/mozsms/index.html @@ -0,0 +1,112 @@ +--- +title: Navigator.mozSms +slug: Web/API/Navigator/mozSms +translation_of: Archive/B2G_OS/API/Navigator/mozSms +--- +<p>{{APIRef("Firefox OS")}}</p> + +<p>{{ non-standard_header() }}</p> + +<p>{{ obsolete_header(25) }}</p> + +<p>{{ B2GOnlyHeader2('certified') }}</p> + +<p>返回 {{ domxref("SmsManager") }} 对象,你可以通过该对象进行短消息的收发操作。</p> + +<div class="note"> +<p>注意: <strong>废弃! </strong>该对象已被废弃,请参考使用: {{ domxref("window.navigator.mozMobileMessage") }}。</p> +</div> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="eval">var sms = window.navigator.mozSms; +</pre> + +<h2 id="参数说明">参数说明</h2> + +<p>这是一个非标准接口,不过该接口有在 W3C 部分提及: <a href="http://www.w3.org/2012/sysapps/" title="http://www.w3.org/2012/sysapps/">System Application Working Group</a>.</p> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Messaging')}}</td> + <td>{{Spec2('Messaging')}}</td> + <td>Editor Draft (WIP).</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容">浏览器兼容</h2> + +<p>For obvious reasons, support is primarily expected on mobile browsers.</p> + +<p>{{ CompatibilityTable() }}</p> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatGeckoMobile("12.0") }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + <td>{{ CompatNo() }}</td> + </tr> + </tbody> +</table> +</div> + +<h2 id="Preferences_availability">Preferences & availability</h2> + +<ul> + <li>WebSMS is disabled by default and can be enabled setting the preference <code>dom.sms.enabled</code> to true.</li> + <li>A comma-separated whitelist of allowed hostnames that are allowed to use the WebSMS API must be specified using the <code>dom.sms.whitelist</code> preference. This string is empty by default.</li> + <li>WebSMS is only available to certified apps on Firefox OS (B2G).</li> +</ul> + +<h2 id="参阅">参阅</h2> + +<ul> + <li><a href="/en-US/docs/API/WebSMS" title="/en-US/docs/API/WebSMS">WebSMS API</a></li> + <li>{{ domxref("SmsManager") }}</li> + <li>{{ domxref("window.navigator.mozTelephony") }} for controlling telephone calls.</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/oscpu/index.html b/files/zh-cn/web/api/navigator/oscpu/index.html new file mode 100644 index 0000000000..95ed7770b0 --- /dev/null +++ b/files/zh-cn/web/api/navigator/oscpu/index.html @@ -0,0 +1,84 @@ +--- +title: Navigator.oscpu +slug: Web/API/Navigator/oscpu +translation_of: Web/API/Navigator/oscpu +--- +<p>{{ ApiRef("HTML DOM") }}</p> + +<h3 id="Summary" name="Summary">概述</h3> + +<p>返回一个字符串,代表当前所使用的操作系统类型.</p> + +<h3 id="Syntax" name="Syntax">语法</h3> + +<pre class="eval"><em>oscpuInfo</em> = window.navigator.oscpu +</pre> + +<ul> + <li><code>oscpuInfo</code> 会有下面几种类型.</li> +</ul> + +<table class="fullwidth-table"> + <tbody> + <tr> + <th>操作系统</th> + <th><code>oscpuInfo</code> 字符串值</th> + </tr> + <tr> + <td>OS/2</td> + <td>OS/2 Warp x (3, 4 或 4.5)</td> + </tr> + <tr> + <td>Windows CE</td> + <td>WindowsCE x.y<sup>1</sup></td> + </tr> + <tr> + <td>Windows 64-bit (64-bit build)</td> + <td>Windows NT x.y; Win64; x64</td> + </tr> + <tr> + <td>Windows 64-bit (32-bit build)</td> + <td>Windows NT x.y; WOW64</td> + </tr> + <tr> + <td>Windows 32-bit</td> + <td>Windows NT x.y</td> + </tr> + <tr> + <td>Mac OS X (PPC build)</td> + <td>PPC Mac OS X x.y</td> + </tr> + <tr> + <td>Mac OS X (i386/x64 build)</td> + <td>Intel Mac OS X x.y</td> + </tr> + <tr> + <td>Linux 64-bit (32-bit build)</td> + <td>命令'uname -s'的输出加上 "i686 on x86_64"</td> + </tr> + <tr> + <td>Linux</td> + <td>命令'uname -sm'的输出</td> + </tr> + </tbody> +</table> + +<p><sup>1</sup>x.y 表示操作系统的版本号</p> + +<h3 id="Example" name="Example">例子</h3> + +<pre class="brush: js">function osInfo() { + alert(window.navigator.oscpu); +} +// 可能返回:"Windows NT 6.1",表示windows 7 +</pre> + +<h3 id="Notes" name="Notes">备注</h3> + +<p>在普通网页中,如果about:config中存在<code>general.oscpu.override项,则</code>该属性的值会返回about:config中<code>general.oscpu.override项的值.</code> 在特权代码中 (chrome上下文或者拥有"UniversalBrowserRead"特权的网页中),返回的还是真实的操作系统类型.(译者注:语句:netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead ")用来激活所在网页的UniversalBrowserRead特权.)</p> + +<h3 id="Specification" name="Specification">规范</h3> + +<p>{{ DOM0() }}</p> + +<p>{{ languages( { "ja": "ja/DOM/window.navigator.oscpu", "en": "en/DOM/window.navigator.oscpu", "pl": "pl/DOM/window.navigator.oscpu" } ) }}</p> diff --git a/files/zh-cn/web/api/navigator/permissions/index.html b/files/zh-cn/web/api/navigator/permissions/index.html new file mode 100644 index 0000000000..bd4510a159 --- /dev/null +++ b/files/zh-cn/web/api/navigator/permissions/index.html @@ -0,0 +1,115 @@ +--- +title: Navigator.permissions +slug: Web/API/Navigator/permissions +tags: + - API + - Permissions + - 属性 +translation_of: Web/API/Navigator/permissions +--- +<p>{{APIRef("HTML DOM")}}{{SeeCompatTable}}</p> + +<p><code><strong>permissions</strong></code> 是 <code><strong>Navigator</strong></code> 读属性,返回一个可用于查询或更新某些APIs(由<a href="/en-US/docs/Web/API/Permissions_API">Permissions API</a>覆盖)的权限状态的对象。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>permissionsObj</em> = <em>globalObj</em>.navigator.permissions +</pre> + +<h2 id="值">值</h2> + +<p>一个 {{domxref("Permissions")}} 对象。</p> + +<h2 id="例子">例子</h2> + +<pre class="brush: js">navigator.permissions.query({name:'geolocation'}).then(function(result) { + if (result.state === 'granted') { + showMap(); + } else if (result.state === 'prompt') { + showButtonToEnableMap(); + } + // 如果被拒绝,请不要做任何操作。 +}); +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规范</th> + <th scope="col">状态</th> + <th scope="col">备注</th> + </tr> + <tr> + <td>{{SpecName('Permissions API')}}</td> + <td>{{Spec2('Permissions API')}}</td> + <td>初始化定义</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器支持">浏览器支持</h2> + +<div>{{ CompatibilityTable() }}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>功能</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>基础支持</td> + <td>{{CompatChrome(43.0)}}</td> + <td>{{CompatGeckoDesktop(46)}}</td> + <td>{{CompatUnknown()}}</td> + <td>{{CompatUnknown()}}</td> + <td>{{CompatUnknown()}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>功能</th> + <th>Android</th> + <th>Android Webview</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>基础支持</td> + <td>{{CompatNo()}}</td> + <td>{{CompatChrome(43.0)}}</td> + <td>{{CompatGeckoMobile(46)}}</td> + <td>{{CompatUnknown()}}<sup>[1]</sup></td> + <td>{{CompatUnknown()}}</td> + <td>{{CompatUnknown()}}</td> + <td>{{CompatUnknown()}}</td> + <td>{{CompatChrome(43.0)}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] Firefox OS 现在采用自己的具有特殊工作方式的 Permissions API:参见 <a href="/en-US/docs/Web/API/Permissions_API_(Firefox_OS)">Permissions API (Firefox OS)</a>.</p> + +<h2 id="See_also" name="See_also">参见</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/Permissions_API">Permissions API</a></li> + <li>{{domxref("Navigator")}}</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/productsub/index.html b/files/zh-cn/web/api/navigator/productsub/index.html new file mode 100644 index 0000000000..afe4655ebc --- /dev/null +++ b/files/zh-cn/web/api/navigator/productsub/index.html @@ -0,0 +1,64 @@ +--- +title: Navigator.productSub +slug: Web/API/Navigator/productSub +tags: + - API + - DOM + - 只读 + - 属性 +translation_of: Web/API/Navigator/productSub +--- +<div>{{ ApiRef("HTML DOM") }}</div> + +<p><code><strong>Navigator.productSub</strong></code> 只读属性返回当前浏览器的编译版本号。 </p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox"><em>prodSub</em> = window.navigator.productSub</pre> + +<ul> + <li><code>prodSub</code>是一个字符串。</li> +</ul> + +<h2 id="Example" name="Example">例子</h2> + +<pre class="brush:js"><script> +function prodsub() { + var dt = document.getElementById("d").childNodes[0]; + dt.data = window.navigator.productSub; +} +</script> + +<button onclick="prodsub();">productSub</button> +// returns: 20010725</pre> + +<h2 id="Notes" name="Notes">注释</h2> + +<p>在IE上,这个属性返回undefined。</p> + +<p>在苹果Safari上和Google的Ghrome上这个属性总是返回20030107。</p> + +<h2 id="说明">说明</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">说明</th> + <th scope="col">状态</th> + <th scope="col">注释</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', '#dom-navigator-productsub', 'NavigatorID: productSub')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Navigator.productSub")}}</p> diff --git a/files/zh-cn/web/api/navigator/registercontenthandler/index.html b/files/zh-cn/web/api/navigator/registercontenthandler/index.html new file mode 100644 index 0000000000..4a858777d6 --- /dev/null +++ b/files/zh-cn/web/api/navigator/registercontenthandler/index.html @@ -0,0 +1,47 @@ +--- +title: Navigator.registerContentHandler() +slug: Web/API/Navigator/registerContentHandler +translation_of: Web/API/Navigator/registerContentHandler +--- +<div>{{ ApiRef("HTML DOM") }}</div> + +<h3 id="Summary" name="Summary">概述</h3> + +<p>Allows web sites to register themselves as possible handlers for content of a particular MIME type.</p> + +<p>{{ Note("Web sites may only register content handlers for themselves. For security reasons, it\'s not possible for an extension or web site to register content handlers targeting other sites.") }}</p> + +<h3 id="Syntax" name="Syntax">语法</h3> + +<pre class="brush: js">window.navigator.registerContentHandler(<em>mimeType</em>, <em>uri</em>, <em>title</em>); +</pre> + +<ul> + <li><code>mimeType</code> is the desired MIME type as a string.</li> + <li><code>uri</code> is the URI to the handler as a string.</li> + <li><code>title</code> is the title of the handler presented to the user as a string.</li> +</ul> + +<h3 id="Example" name="Example">例子</h3> + +<pre class="brush: js">navigator.registerContentHandler("application/vnd.mozilla.maybe.feed", + "<span class="plain">http://www.example.tld/?foo=%s</span>", + "My Feed Reader"); +</pre> + +<h3 id="Notes" name="Notes">备注</h3> + +<p>For <a href="/zh-cn/Firefox_2_for_developers" title="zh-cn/Firefox_2_for_developers">Firefox 2</a> and above, only the <code>application/vnd.mozilla.maybe.feed</code>, <code>application/atom+xml</code>, and <code>application/rss+xml</code> MIME types are supported. All values have the same effect, and the registered handler will receive feeds in all Atom and RSS versions (see {{ Bug("391286") }}).</p> + +<h3 id="Specification" name="Specification">规范</h3> + +<p>WHATWG's <a class="external" href="http://whatwg.org/specs/web-apps/current-work/#custom-handlers">Web Applications 1.0 工作草案</a></p> + +<h3 id="相关链接">相关链接</h3> + +<ul> + <li><a href="/zh-cn/Web-based_protocol_handlers" title="zh-cn/Web-based_protocol_handlers">Web-based protocol handlers</a></li> + <li><a href="/zh-cn/nsIContentHandler" title="zh-cn/nsIContentHandler">nsIContentHandler</a> (XUL only)</li> +</ul> + +<p>{{ languages( { "ja": "ja/DOM/window.navigator.registerContentHandler", "en": "en/DOM/window.navigator.registerContentHandler", "pl": "pl/DOM/window.navigator.registerContentHandler" } ) }}</p> diff --git a/files/zh-cn/web/api/navigator/registerprotocolhandler/index.html b/files/zh-cn/web/api/navigator/registerprotocolhandler/index.html new file mode 100644 index 0000000000..b51348f2ef --- /dev/null +++ b/files/zh-cn/web/api/navigator/registerprotocolhandler/index.html @@ -0,0 +1,151 @@ +--- +title: Navigator.registerProtocolHandler() +slug: Web/API/Navigator/registerProtocolHandler +tags: + - API + - Navigator + - URL protocols + - URL schemes + - registerProtocolHandler + - 自定义 URL 协议 + - 自定义 URL 方案 +translation_of: Web/API/Navigator/registerProtocolHandler +--- +<div>{{APIRef("HTML DOM")}}{{securecontext_header}}</div> + +<p><strong>{{domxref("Navigator")}}</strong> 的方法 <code><strong>registerProtocolHandler()</strong></code> 让 web 站点为自身注册用于打开或处理特定 URL 方案(又名协议)的能力。</p> + +<p>举个例子,此API允许Web邮件站点打开 <code>mailto:</code> URL,或让 <abbr title="Voice over Internet Protocol, also called IP telephony">VoIP</abbr> 站点打开 <code>tel:</code> URL。</p> + +<h2 id="语法">语法</h2> + +<pre class="notranslate">navigator.registerProtocolHandler(<var>scheme</var>, <var>url</var>, <var>title</var>); +</pre> + +<div class="blockIndicator note"> +<p><strong>Note:</strong> 最近更新为 <code>navigator.registerProtocolHandler(<var>scheme</var>, <var>url</var>)</code>, 但目前没有浏览器支持该版本。</p> +</div> + +<h3 id="参数">参数</h3> + +<dl> + <dt><code><var>scheme</var></code></dt> + <dd>一个包含站点希望处理的协议的字符串。例如,你可以通过传入 <code>"sms"</code> 来注册处理SMS文本信息链接。</dd> +</dl> + +<dl> + <dt><code>url</code></dt> + <dd>处理器的URL,string类型。这个字符串应该包含一个"%s"的占位符,其会被将要受理的文档的 <a href="https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent">escaped</a> 链接所替换。这个链接(译者按:指将要受理的文档的 escaped 链接,也就是替换占位符的字符串)可能是一个真实的URL,或者是一个电话号码,邮件地址之类的。</dd> + <dd> + <div class="note">这个处理器的 URL 必须以 <code>http</code> 或者 <code>https</code> 协议标记作为开头,最好是 <code>https</code> ,以满足一些浏览器出于安全考虑的要求。</div> + </dd> + <dt><code>title {{Obsolete_Inline}}</code></dt> + <dd>一个用户可理解的处理器标题。标题会展示给用户,例如弹出对话框“允许这个站点处理[scheme]链接吗?”或者在浏览器设置中列出注册的处理器时。</dd> + <dd> + <div class="blockIndicator note"> + <p><strong>Note:</strong> 出于欺骗的考虑,标题已从规范中删除,但当前所有的浏览器仍要求使用该标题。 建议始终设置标题,因为支持更新规范的浏览器很可能会向后兼容,并且仍接受标题(但不使用它)。</p> + </div> + </dd> + <dd></dd> +</dl> + +<h3 id="异常">异常</h3> + +<ul> + <li>指定了一个非法的协议标记,例如一个浏览器自身的标记(<code>https:</code>, <code>about:</code> 等)。</li> + <li>处理器URL的 <a href="https://wiki.developer.mozilla.org/en-US/docs/Glossary/Origin">origin</a> 与调用这个API的页面的 origin不匹配。</li> + <li>浏览器要求这个函数由安全的上下文调用。</li> + <li>浏览器要求处理器的URL使用 HTTPS 协议。</li> +</ul> + +<dl> + <dt><code>SecurityError</code></dt> + <dd>用户代理阻止了处理器的注册。这可能是由于:</dd> + <dt><code>SyntaxError</code></dt> + <dd>在指定的协议处理地址的字符串中缺失了 <code>%s</code> 占位符.</dd> +</dl> + +<h2 id="允许的协议标记">允许的协议标记</h2> + +<p>出于安全考虑,<code>registerProtocolHandler()</code> 严格限制了允许注册的协议标记。以 <code>web+</code> 作为前缀的方式可以注册一个自定义的标记协议,至少要有5个字符的长度(包括 <code>web+</code> 前缀),而且只能使用小写的ASCII字母作为名称。例如 <code>web+burger</code> ,如下面的{{anch("示例")}}所示。</p> + +<p>除此之外,还可以使用下文所列的白名单中的协议标记:</p> + +<div class="threecolumns"> +<ul> + <li><code>bitcoin</code></li> + <li><code>geo</code></li> + <li><code>im</code></li> + <li><code>irc</code></li> + <li><code>ircs</code></li> + <li><code>magnet</code></li> + <li><code>mailto</code></li> + <li><code>mms</code></li> + <li><code>news</code></li> + <li><code>nntp</code></li> + <li><code>openpgp4fpr</code></li> + <li><code>sip</code></li> + <li><code>sms</code></li> + <li><code>smsto</code></li> + <li><code>ssh</code></li> + <li><code>tel</code></li> + <li><code>urn</code></li> + <li><code>webcal</code></li> + <li><code>wtai</code></li> + <li><code>xmpp</code></li> +</ul> +</div> + +<h2 id="示例">示例</h2> + +<p>如果您的网站是 <code>https://www.google.com/</code>,则可以为其注册一个协议处理程序来处理 <code>web+burger:</code>链接,如下所示:</p> + +<pre class="brush: js notranslate">navigator.registerProtocolHandler("web+burger", + "https://www.google.com/?uri=%s", + "Burger handler"); +</pre> + +<p>这将创建一个处理程序,该处理程序允许使用 <code>web+burger: </code>链接将用户发送到您的网站,并将访问的 Burger URL插入<code>%s</code>占位符。</p> + +<p>该脚本必须从与处理程序URL相同的源运行(因此, <code>https://www.google.com/ </code>上的任何页面),并且处理程序URL必须为 <code>http </code>或 <code>https</code>。</p> + +<p>将通知用户您的代码要求注册协议处理程序,以便他们可以决定是否允许它。有关 <code>https://www.google.com/ </code>上的示例,请参见以下屏幕截图:</p> + +<p><img alt="" src="https://mdn.mozillademos.org/files/9683/protocolregister.png"></p> + +<div class="note"> +<p>"<a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWebContentHandlerRegistrar#Getting_most_recent_window">Register a webmail service as mailto handler</a>" 展示了如何从跨平台组件对象模块(XPCOM)中做到这一切.</p> +</div> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('HTML WHATWG', 'webappapis.html#dom-navigator-registerprotocolhandler', 'registerProtocolHandler()')}}</td> + <td>{{Spec2('HTML WHATWG')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<p>{{Compat("api.Navigator.registerProtocolHandler")}}</p> + +<h2 id="参见">参见</h2> + +<ul> + <li><a href="/en-US/docs/Web-based_protocol_handlers">Web-based protocol handlers</a></li> + <li><a href="http://blog.mozilla.com/webdev/2010/07/26/registerprotocolhandler-enhancing-the-federated-web/">RegisterProtocolHandler Enhancing the Federated Web</a> at Mozilla Webdev</li> + <li><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#whitelisted-scheme">Web Application APIs - Custom scheme and content handlers - Whitelisted schemes</a></li> + <li><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWebContentHandlerRegistrar#Getting_most_recent_window">Register a webmail service as mailto handler</a> shows how to do <code>registerProtocolHandler</code> from XPCOM scope.</li> + <li><a href="/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWebContentHandlerRegistrar#registerProtocolHandler">XPCOM Interface Reference > nsIWebContentHandlerRegistrar > registerContentHandler</a> - This shows how to use this function XPCOM scope</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/registerprotocolhandler/web-based_protocol_handlers/index.html b/files/zh-cn/web/api/navigator/registerprotocolhandler/web-based_protocol_handlers/index.html new file mode 100644 index 0000000000..34085a54f2 --- /dev/null +++ b/files/zh-cn/web/api/navigator/registerprotocolhandler/web-based_protocol_handlers/index.html @@ -0,0 +1,133 @@ +--- +title: Web-based protocol handlers +slug: Web/API/Navigator/registerProtocolHandler/Web-based_protocol_handlers +translation_of: Web/API/Navigator/registerProtocolHandler/Web-based_protocol_handlers +--- +<div>{{Fx_minversion_header(3)}}</div> + +<h2 id="Background" name="Background">背景</h2> + +<p>利用非http协议,从网页链接到一些别的资源,这种做法是相当普遍的。比如 <code>mailto:</code> 协议:</p> + +<div style="overflow: hidden;"> +<pre class="brush:html"><a href="mailto:webmaster@example.com">Web Master</a></pre> +</div> + +<p>当Web页面作者想直接从网页上,为用户提供一个方便的方式发送一个电子邮件,时可以使用mailto:链接。激活链接时,浏览器应该启动默认的桌面应用程序来处理电子邮件。你可以认为这是一个<em>基于桌面的</em>协议处理器。</p> + +<p>基于网络的协议处理程序也允许基于web的应用程序参与这一过程。随着越来越多的类型的应用程序迁移到web,这变得越来越重要。事实上,有许多基于web的电子邮件处理的应用程序可以处理一个mailto链接。</p> + +<h2 id="Registering" name="Registering">注册</h2> + +<p>设置一个web应用程序作为一个协议处理器不是一个很麻烦的过程。web应用程序可以使用<a href="/en-US/docs/Web/API/navigator.registerProtocolHandler">registerProtocolHandler()</a>注册到浏览器上,从而对于一个给定的协议来讲,作为一个潜在的处理程序。例如:</p> + +<pre class="brush: js">navigator.registerProtocolHandler("mailto", + "https://www.example.com/?uri=%s", + "Example Mail"); +</pre> + +<p>参数为:</p> + +<ul> + <li>协议名称.</li> + <li>url模板。%s用来替换链接的<code>href</code>属性,之后通过这个url来发起一个GET请求.</li> + <li>一个对用户友好的协议处理器的名字.</li> +</ul> + +<p>当一个浏览器执行这段代码时,它应该向用户显示一个请求,让用户许可为处理这个协议而注册一个web应用程序的请求。Firefox在通知栏区域显示一个提示:</p> + +<p><img alt="Image:wph-notification.png" src="/@api/deki/files/972/=Wph-notification.png"></p> + +<div class="note"><strong>Note:</strong>试图执行登记或注册时,当前网页必须与提供的URL模板在相同的域,否则将会失败。例如,http://example.com/homepage.html可以为<code class="plain" style="font-size: 14px;">http://example.com/handle_mailto/%s</code><span style="line-height: 1.5;">注册一个协议处理程序</span><span style="line-height: 1.5em;">, 但</span><code class="plain" style="font-size: 14px;">http://example.<em><strong>org</strong></em>/handle_mailto/%s不可以</code><span style="line-height: 1.5em;">.</span></div> + +<p> </p> + +<p>多次注册相同的协议处理程序会弹出不同的通知,表明协议处理器已经注册。因此,发起一个注册协议处理程序的请求,之后检查是否注册是一个很好的方法。比如下面的例子。</p> + +<h3 id="Example" name="Example">例子</h3> + +<pre class="brush: js"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> +<html lang="en"> +<head> + <title>Web Protocol Handler Sample - Register</title> + <script type="text/javascript"> + var url = "http://starkravingfinkle.org/projects/wph/handler.php?value=%s"; + if (!navigator.isProtocolHandlerRegistered("fake", url)) { + navigator.registerProtocolHandler("fake", url, "Fake Protocol"); + } + </script> +</head> +<body> + <h1>Web Protocol Handler Sample</h1> + <p>This web page will install a web protocol handler for the <code>fake:</code> protocol.</p> +</body> +</html> +</pre> + +<h2 id="Activating" name="Activating">激活</h2> + +<p>现在,只要用户点击链接,使用注册协议,浏览器将跳转到web应用程序注册时提供的URL。Firefox在默认情况下,跳转前会提示用户操作。</p> + +<p><img alt="Image:wph-launch.png" src="/@api/deki/files/971/=Wph-launch.png"></p> + +<h3 id="Example_2" name="Example_2">Example</h3> + +<pre class="brush: html"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> +<html lang="en"> +<head> + <title>Web Protocol Handler Sample - Test</title> +</head> +<body> + <p>Hey have you seen <a href="fake:this%20is%20fake">this</a> before?</p> +</body> +</html> +</pre> + +<h2 id="Handling" name="Handling">处理</h2> + +<p>下一步是处理这个动作。浏览器在激活的链接中提取出href属性,之后与注册时提供的URL模板进行拼装,之后经由拼装好的URL发起一个HTTP GET请求.因此下面的例子中,浏览器会基于此URL发起一个GET请求:</p> + +<pre>http://starkravingfinkle.org/projects/wph/handler.php?value=fake:this%20is%20fake</pre> + +<p>服务端代码可以提取查询字符串的参数,执行所需的操作。</p> + +<div class="note"><strong>Note:</strong>服务端代码会接收到href的<strong>全部</strong>内容。这意味着服务端代码必须解析出数据中的协议。</div> + +<h3 id="Example_3" name="Example_3">Example</h3> + +<pre class="brush: php"><?php +$value = ""; +if ( isset ( $_GET["value"] ) ) { + $value = $_GET["value"]; +} +?> + +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> +<html lang="en"> +<head> + <title>Web Protocol Handler Sample</title> +</head> +<body> + <h1>Web Protocol Handler Sample - Handler</h1> + <p>This web page is called when handling a <code>fake:</code> protocol action. The data sent:</p> + <textarea> +<?php echo(htmlspecialchars($value, ENT_QUOTES, 'UTF-8')); ?> + </textarea> +</body> +</html> +</pre> + +<h2 id="References" name="References">参考</h2> + +<ul> + <li><a href="http://www.w3.org/TR/2011/WD-html5-20110525/timers.html#custom-handlers">http://www.w3.org/TR/2011/WD-html5-20110525/timers.html#custom-handlers</a></li> +</ul> + +<h2 id="See_also" name="See_also">See also</h2> + +<ul> + <li><a href="/en-US/docs/DOM/window.navigator.registerContentHandler" title="DOM/window.navigator.registerContentHandler">window.navigator.registerContentHandler</a></li> + <li><a href="/en-US/docs/XPCOM_Interface_Reference/nsIProtocolHandler" title="nsIProtocolHandler">nsIProtocolHandler</a> (XUL only)</li> + <li><a class="external" href="http://blog.mozilla.com/webdev/2010/07/26/registerprotocolhandler-enhancing-the-federated-web/" title="http://blog.mozilla.com/webdev/2010/07/26/registerprotocolhandler-enhancing-the-federated-web/">RegisterProtocolHandler Enhancing the Federated Web</a> at Mozilla Webdev</li> + <li><a href="https://developers.google.com/web/updates/2011/06/Registering-a-custom-protocol-handler">Register a custom protocolHandler</a> at Google Developers.</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/sendbeacon/index.html b/files/zh-cn/web/api/navigator/sendbeacon/index.html new file mode 100644 index 0000000000..76ebbe89a8 --- /dev/null +++ b/files/zh-cn/web/api/navigator/sendbeacon/index.html @@ -0,0 +1,95 @@ +--- +title: Navigator.sendBeacon() +slug: Web/API/Navigator/sendBeacon +tags: + - API + - Beacon + - Web Performance + - sendBeacon +translation_of: Web/API/Navigator/sendBeacon +--- +<div> {{APIRef("HTML DOM")}}</div> + +<p><code><strong>navigator.sendBeacon()</strong></code> 方法可用于通过{{Glossary("HTTP")}}将少量数据异步传输到Web服务器。</p> + +<h2 id="语法">语法</h2> + +<pre>navigator.sendBeacon(<em>url, </em><em>data</em>);</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><code>url</code></dt> + <dd><code>url</code> 参数表明 <code>data</code> 将要被发送到的网络地址。</dd> +</dl> + +<dl> + <dt><code>data</code></dt> + <dd><code>data</code> 参数是将要发送的 {{domxref("ArrayBufferView")}} 或 {{domxref("Blob")}}, {{domxref("DOMString")}} 或者 {{domxref("FormData")}} 类型的数据。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>当用户代理成功把数据加入传输队列时,<strong><code>sendBeacon()</code></strong> 方法将会返回 <code>true</code>,否则返回 <code>false</code>。</p> + +<h2 id="描述">描述</h2> + +<p>这个方法主要用于满足统计和诊断代码的需要,这些代码通常尝试在卸载(unload)文档之前向web服务器发送数据。过早的发送数据可能导致错过收集数据的机会。然而,对于开发者来说保证在文档卸载期间发送数据一直是一个困难。因为用户代理通常会忽略在 {{event("unload")}} 事件处理器中产生的异步 {{domxref("XMLHttpRequest")}}。</p> + +<p>为了解决这个问题, 统计和诊断代码通常要在 <code>unload</code> 或者 {{event("beforeunload")}} 事件处理器中发起一个同步 <code>XMLHttpRequest</code> 来发送数据。同步的 <code>XMLHttpRequest</code> 迫使用户代理延迟卸载文档,并使得下一个导航出现的更晚。下一个页面对于这种较差的载入表现无能为力。</p> + +<p>有一些技术被用来保证数据的发送。其中一种是通过在卸载事件处理器中创建一个图片元素并设置它的 src 属性的方法来延迟卸载以保证数据的发送。因为绝大多数用户代理会延迟卸载以保证图片的载入,所以数据可以在卸载事件中发送。另一种技术是通过创建一个几秒钟的 no-op 循环来延迟卸载并向服务器发送数据。</p> + +<p>这些技术不仅编码模式不好,其中的一些甚至并不可靠而且会导致非常差的页面载入性能。</p> + +<p>下面的例子展示了一个理论上的统计代码——在卸载事件处理器中尝试通过一个同步的 <code>XMLHttpRequest</code> 向服务器发送数据。这导致了页面卸载被延迟。</p> + +<pre class="brush: js">window.addEventListener('unload', logData, false); + +function logData() { + var client = new XMLHttpRequest(); + client.open("POST", "/log", false); // 第三个参数表明是同步的 xhr + client.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); + client.send(analyticsData); +} +</pre> + +<p>这就是 <strong><code>sendBeacon()</code></strong> 方法存在的意义。使用 <strong><code>sendBeacon() </code></strong>方法会使用户代理在有机会时异步地向服务器发送数据,同时不会延迟页面的卸载或影响下一导航的载入性能。这就解决了提交分析数据时的所有的问题:数据可靠,传输异步并且不会影响下一页面的加载。此外,代码实际上还要比其他技术简单许多!</p> + +<p>下面的例子展示了一个理论上的统计代码模式——通过使用 <strong><code>sendBeacon()</code></strong> 方法向服务器发送数据。</p> + +<pre class="brush: js">window.addEventListener('unload', logData, false); + +function logData() { + navigator.sendBeacon("/log", analyticsData); +} +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Beacon', '#sec-sendBeacon-method', 'sendBeacon()')}}</td> + <td>{{Spec2('Beacon')}}</td> + <td>Initial definition</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Navigator.sendBeacon")}}</p> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>{{domxref("navigator", "navigator")}}</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/serviceworker/index.html b/files/zh-cn/web/api/navigator/serviceworker/index.html new file mode 100644 index 0000000000..16cf2ac51d --- /dev/null +++ b/files/zh-cn/web/api/navigator/serviceworker/index.html @@ -0,0 +1,97 @@ +--- +title: Navigator.serviceWorker +slug: Web/API/Navigator/serviceWorker +translation_of: Web/API/Navigator/serviceWorker +--- +<p>{{APIRef("Service Workers API")}}</p> + +<p><code><strong>Navigator.serviceWorker</strong></code> 只读属性,返回 <a href="https://html.spec.whatwg.org/multipage/browsers.html#concept-document-window">关联文件</a> 的 {{domxref("ServiceWorkerContainer")}} 对象,它提供对{{domxref("ServiceWorker")}} 的注册,删除,升级和通信的访问。。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">let workerContainerInstance = navigator.serviceWorker; +</pre> + +<h3 id="值">值</h3> + +<p>{{domxref("ServiceWorkerContainer")}}.</p> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Service Workers', '#navigator-service-worker', 'navigator.serviceWorker')}}</td> + <td>{{Spec2('Service Workers')}}</td> + <td>Initial definition.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(40.0)}}</td> + <td>{{ CompatGeckoDesktop("44.0") }}<sup>[1]</sup></td> + <td>{{CompatNo}}</td> + <td>24</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>Firefox OS</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatUnknown}}</td> + <td>{{ CompatGeckoMobile("44.0") }}</td> + <td>{{ CompatVersionUnknown }}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatUnknown}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] Service workers (and <a href="/en-US/docs/Web/API/Push_API">Push</a>) have been disabled in the <a href="https://www.mozilla.org/en-US/firefox/organizations/">Firefox 45 Extended Support Release</a> (ESR.)</p> + +<h2 id="也可以看看">也可以看看</h2> + +<ul> + <li><a href="/en-US/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li> + <li><a href="/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Using Service Workers</a></li> +</ul> diff --git a/files/zh-cn/web/api/navigator/share/index.html b/files/zh-cn/web/api/navigator/share/index.html new file mode 100644 index 0000000000..3a0f14dba3 --- /dev/null +++ b/files/zh-cn/web/api/navigator/share/index.html @@ -0,0 +1,97 @@ +--- +title: Navigator.share +slug: Web/API/Navigator/share +tags: + - Navitator + - Share + - Web Share +translation_of: Web/API/Navigator/share +--- +<div>{{APIRef("HTML DOM")}}{{SeeCompatTable}} {{securecontext_header}}</div> + +<p><strong><code>Navigator.share()</code></strong><font><font>方法通过调用本机的共享机制作为Web Share API的一部分。</font><font>如果不支持Web Share API,则此方法为</font></font><code>undefined</code><font><font>。</font></font></p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox notranslate">const sharePromise = window.navigator.share(<var>data</var>); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><var>data</var></dt> + <dd><font>包含要共享的数据的对象。</font><font>必须至少指定以下字段之一。</font><font>可用选项包括:</font></dd> +</dl> + +<ul> + <li><code>url</code>: 要共享的URL( {{domxref("USVString")}} )</li> + <li><code>text</code>: 要共享的文本( {{domxref("USVString")}} )</li> + <li><code>title</code>: 要共享的标题( {{domxref("USVString")}})</li> + <li><code>files</code>: 要共享的文件(“FrozenArray”)</li> +</ul> + +<dl> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>该方法将会返回一个{{jsxref("Promise")}}。一旦用户完成分享,这个promise将会接受 。如果指定的共享数据格式不正确,promise将会立即拒绝;如果用户取消了分享,promise也会拒绝。</p> + +<p>例如, 在Android的Chrome上, 将在用户选择要共享的应用程序后将会解析共享的内容。.</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js notranslate">navigator.share({ + title: document.title, + text: 'Hello World', + url: 'https://developer.mozilla.org', +}); // 分享MDN的URL</pre> + +<h4 id="分享文件"><strong>分享文件</strong></h4> + +<p>分享文件之前,先使用<code>navigator.canShare()</code>.判断这个文件能否被分享,Then include an array of files in the call to <code>navigator.share():</code></p> + +<p>Notice: That the sample handles feature detection by testing for <code>navigator.canShare()</code> rather than for <code>navigator.share()</code>. The data object passed to <code>canShare()</code> only supports the <code>files</code> property. Image, video, audio, and text files can be shared.</p> + +<pre class="brush: js notranslate">if (navigator.canShare && navigator.canShare({ files: filesArray })) { + navigator.share({ + files: filesArray, + title: 'Pictures', + text: 'Our Pictures.', + }) + .then(() => console.log('Share was successful.')) + .catch((error) => console.log('Sharing failed', error)); +} else { + console.log(`Your system doesn't support sharing files.`); +}</pre> + +<h2 id="规范">规范</h2> + +<table> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Web Share API','#share-method','share()')}}</td> + <td>{{Spec2('Web Share API')}}</td> + <td></td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + + + +<p>{{Compat("api.Navigator.share")}}</p> + +<h2 id="参见">参见</h2> + +<ul> + <li>{{domxref("navigator.canShare()")}}</li> +</ul> diff --git a/files/zh-cn/web/api/navigator/vendor/index.html b/files/zh-cn/web/api/navigator/vendor/index.html new file mode 100644 index 0000000000..3dffcea6f4 --- /dev/null +++ b/files/zh-cn/web/api/navigator/vendor/index.html @@ -0,0 +1,37 @@ +--- +title: Navigator.vendor +slug: Web/API/Navigator/vendor +translation_of: Web/API/Navigator/vendor +--- +<p>{{ ApiRef() }}</p> + +<h3 id="Summary" name="Summary">概述</h3> + +<p>返回当前所使用浏览器的浏览器供应商的名称.</p> + +<h3 id="Syntax" name="Syntax">语法</h3> + +<pre class="eval"><em>venString</em> = window.navigator.vendor +</pre> + +<h3 id="Parameters" name="Parameters">参数</h3> + +<ul> + <li><code>venString</code> 浏览器供应商.</li> +</ul> + +<h3 id="Example" name="Example">例子</h3> + +<pre>window.navigator.vendor +// 返回 "Netscape6" +</pre> + +<h3 id="Notes" name="Notes">备注</h3> + +<p>vendor属性值也是组成userAgent字符串的一部分.product属性值和vendor属性值可以是不同的,比如在firefox中,两者的值表示:Netscape 6.1使用Gecko来渲染网页. 想了解更多,请查看 <a href="/zh-cn/DOM/window.navigator.product" title="zh-cn/DOM/window.navigator.product">navigator.product</a>, <a href="/zh-cn/DOM/window.navigator.userAgent" title="zh-cn/DOM/window.navigator.userAgent">navigator.userAgent</a></p> + +<h3 id="Specification" name="Specification">规范</h3> + +<p>{{ DOM0() }}</p> + +<p>{{ languages( { "ja": "ja/DOM/window.navigator.vendor" ,"en": "en/DOM/window.navigator.vendor" } ) }}</p> diff --git a/files/zh-cn/web/api/navigator/vendorsub/index.html b/files/zh-cn/web/api/navigator/vendorsub/index.html new file mode 100644 index 0000000000..20e2ecb91e --- /dev/null +++ b/files/zh-cn/web/api/navigator/vendorsub/index.html @@ -0,0 +1,37 @@ +--- +title: Navigator.vendorSub +slug: Web/API/Navigator/vendorSub +translation_of: Web/API/Navigator/vendorSub +--- +<p>{{ ApiRef() }}</p> + +<h3 id="Summary" name="Summary">概述</h3> + +<p><strong>vendorSub</strong> navigator.vendor的值的一部分,表示浏览器供应商的版本号。</p> + +<h3 id="Syntax" name="Syntax">语法</h3> + +<pre class="eval"><em>venSub</em> = window.navigator.vendorSub +</pre> + +<h3 id="Parameters" name="Parameters">参数</h3> + +<ul> + <li><code>venSub</code>是个字符串.</li> +</ul> + +<h3 id="Example" name="Example">例子</h3> + +<pre>window.navigator.vendorSub +// 返回"6.1",该值还作为navigator.userAgent的值的一部分. +</pre> + +<h3 id="Notes" name="Notes">备注</h3> + +<p>vendorSub的属性值也是一个组成navigator.userAgent字符串的一部分. 表示浏览器供应商给该当前浏览器的版本号 (可能和navigator.productSub属性值不同). 在navigator.vendor等于"Netscape 6.1"时, navigator.productSub为 "5.0",navigator.vendorSub为"6.1".想要了解更多,请查看 <a href="/zh-cn/DOM/window.navigator.productSub" title="zh-cn/DOM/window.navigator.productSub">navigator.productSub</a>, <a href="/zh-cn/DOM/window.navigator.userAgent" title="zh-cn/DOM/window.navigator.userAgent">navigator.userAgent</a>, <a href="/zh-cn/DOM/window.navigator.vendor" title="zh-cn/DOM/window.navigator.vendor">navigator.vendor</a></p> + +<h3 id="Specification" name="Specification">规范</h3> + +<p>{{ DOM0() }}</p> + +<p>{{ languages( {"ja": "ja/DOM/window.navigator.vendorSub","en": "en/DOM/window.navigator.vendorSub" } ) }}</p> diff --git a/files/zh-cn/web/api/navigator/vibrate/index.html b/files/zh-cn/web/api/navigator/vibrate/index.html new file mode 100644 index 0000000000..30dcc9d839 --- /dev/null +++ b/files/zh-cn/web/api/navigator/vibrate/index.html @@ -0,0 +1,115 @@ +--- +title: Navigator.vibrate() +slug: Web/API/Navigator/vibrate +translation_of: Web/API/Navigator/vibrate +--- +<p>{{APIRef("HTML DOM")}}</p> + +<p><strong><code>Navigator.vibrate()</code></strong> 方法使设备(有震动硬件)产生有频率的震动。若设备不支持震动,该方法将无效。若某震动方式已经在进行中(当该方法调用时),则前一个震动方式停止,新的取而代之。</p> + +<p>该方法若因为提供无效的参数使得无法使设备震动,它将返回false,否则返回true。若振动方案导致长时间的震动,它会被截断:最大震动时长取决于每个浏览器的具体实现。</p> + +<h2 id="Syntax" name="Syntax">语法</h2> + +<pre class="syntaxbox">var <em>successBool</em> = window.navigator.vibrate(<em><var>pattern</var></em>); +</pre> + +<dl> + <dt><em>pattern</em></dt> + <dd>提供一个震动、暂停间隔的模式。每一个值表示交替震动或者暂停的毫秒数。你可以提供一个单个的值(震动一次的毫秒数)或者一个包含整数的数组来交替的震动、暂停、震动。详情参见 <a href="/en-US/docs/WebAPI/Vibration" title="/en-US/docs/WebAPI/Vibration">Vibration API</a>。</dd> +</dl> + +<p>传递一个 <code>0</code>、一个空数组或者一个元素全部为 <code>0</code> 的数组会结束当前正在运行中的震动模式。</p> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">window.navigator.vibrate(200); // vibrate for 200ms +window.navigator.vibrate([100,30,100,30,100,200,200,30,200,30,200,200,100,30,100,30,100]); // Vibrate 'SOS' in Morse. +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('Vibration API')}}</td> + <td>{{Spec2('Vibration API')}}</td> + <td>Linked to spec is the latest editor's draft; W3C version is a REC.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoDesktop("11.0")}} {{property_prefix("moz")}}<br> + {{CompatGeckoDesktop("16.0")}} (no prefix) [1]</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android Webview</th> + <th>Chrome for Android</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Mobile</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatVersionUnknown}} {{property_prefix("webkit")}}<br> + {{CompatVersionUnknown}} (unprefixed) [2][3]</td> + <td>{{CompatVersionUnknown}} {{property_prefix("webkit")}}<br> + {{CompatVersionUnknown}} (unprefixed) [2][3]</td> + <td>{{CompatGeckoMobile("11.0")}} {{property_prefix("moz")}}<br> + {{CompatGeckoMobile("16.0")}} (no prefix) [1]</td> + <td>{{CompatNo}}</td> + <td>{{CompatVersionUnknown}}<sup>[3]</sup></td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<p>[1] 当震动模式太长或者其中一次震动的时长太长时,截至 Firefox 26,Gecko 将会抛出一个异常,而不是返回 <code>false</code> ({{bug("884935")}})。从 Firefox 32 开始,Gecko 返回 <code>true</code>,但是会将该模式截断 ({{bug(1014581)}})。</p> + +<p>[2] 从 Chrome 55 开始,跨域的 iframe 中不支持该 API。</p> + +<p>[3] 从 Chrome 60/Opera 47 开始,该方法需要一个用户手势。否则会返回 <code>false</code>。</p> + +<h2 id="更多">更多</h2> + +<ul> + <li><a href="/en-US/docs/WebAPI/Vibration" title="/en-US/docs/WebAPI/Vibration">Vibration API</a></li> +</ul> |