Window.navigator

  • Revision slug: DOM/window.navigator
  • Revision title: window.navigator
  • Revision id: 375517
  • Created:
  • Creator: Jeremie
  • Is current revision? No
  • Comment

Revision Content

{{DomRef}}

Summary

Returns a reference to the navigator object, which can be queried for information about the application running the script.

Example

alert("You're using " + navigator.appName);

Properties

Standard

{{domxref("window.navigator.appName", "navigator.appName")}}
Returns the official name of the browser. Do not rely on this property to return the correct value.
{{domxref("window.navigator.appVersion", "navigator.appVersion")}}
Returns the version of the browser as a string. Do not rely on this property to return the correct value.
{{domxref("window.navigator.battery", "navigator.battery")}} {{gecko_minversion_inline("10.0")}}
Returns a {{domxref("window.navigator.battery", "battery")}} object you can use to get information about the battery charging status.
{{domxref("window.navigator.connection", "navigator.connection")}}
Provides information about the network connection of a device.
{{domxref("window.navigator.cookieEnabled", "navigator.cookieEnabled")}}
Returns a boolean indicating whether cookies are enabled in the browser or not.
{{domxref("window.navigator.language", "navigator.language")}}
Returns a string representing the language version of the browser.
{{domxref("window.navigator.mimeTypes", "navigator.mimeTypes")}}
Returns a list of the MIME types supported by the browser.
{{domxref("window.navigator.onLine", "navigator.onLine")}}
Returns a boolean indicating whether the browser is working online.
{{domxref("window.navigator.oscpu", "navigator.oscpu")}}
Returns a string that represents the current operating system.
{{domxref("window.navigator.platform", "navigator.platform")}}
Returns a string representing the platform of the browser.
{{domxref("window.navigator.plugins", "navigator.plugins")}}
Returns an array of the plugins installed in the browser.
{{domxref("window.navigator.userAgent", "navigator.userAgent")}}
Returns the user agent string for the current browser.

Non standard

{{domxref("window.navigator.appCodeName", "navigator.appCodeName")}} {{non-standard_inline}}
Returns the internal "code" name of the current browser. Do not rely on this property to return the correct value.
{{domxref("window.navigator.buildID", "navigator.buildID")}} {{non-standard_inline}}
Returns the build identifier of the browser (e.g. "2006090803")
{{domxref("navigator.doNotTrack")}} {{non-standard_inline}}
Reports the value of the user's do-not-track preference. When this value is "yes", your web site or application should not track the user.
{{domxref("navigator.id")}} {{non-standard_inline}}
Returns the {{domxref("window.navigator.id", "id")}} object which you can use to add support for BrowserID to your web site.
{{domxref("window.navigator.mozAlarms","navigator.mozAlarms")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}
Returns a {{domxref("MozAlarmsManager", "MozAlarmsManager")}} object you can use to schedule notifications or applications to be started at a specific time.
{{domxref("window.navigator.mozApps", "navigator.mozApps")}} {{non-standard_inline}}
Returns an {{domxref("window.navigator.mozApps", "Apps")}} object you can use to install, manage, and control Open Web apps.
{{domxref("window.navigator.mozCameras", "navigator.mozCameras")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}
Return a {{domxref("CameraManager")}} object you can use to access cameras available on your device.
{{domxref("navigator.mozMobileConnection")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}
Return a MozMobileConnection object to retrieve the connection states of a mobile device and to perform some SIM/RUIM card actions.
{{domxref("navigator.mozNotification")}} {{MobileOnlyInline("2.0")}} {{non-standard_inline}}
{{domxref("navigator.webkitNotification")}}
Returns a {{domxref("navigator.mozNotification", "notification")}} object you can use to deliver notifications to the user from your web application.
{{domxref("window.navigator.mozPower", "navigator.mozPower")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}
Returns a {{domxref("PowerManager")}} object that allow to control the power usage and turn off unused peripherals to save power.
{{domxref("window.navigator.mozSettings", "navigator.mozSettings")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}
Returns a {{domxref("SettingsManager")}} object you can use to access the device's settings
{{domxref("window.navigator.mozSms", "navigator.mozSms")}} {{b2g_required_inline("1.0")}} {{gecko_minversion_inline("12.0")}} {{non-standard_inline}}
Returns a {{domxref("SmsManager")}} object you can use to manage SMS messaging in your web application.
{{domxref("navigator.mozSocial")}} {{non-standard_inline}}
{{todo("NeedsText")}}
{{domxref("window.navigator.mozTelephony", "navigator.mozTelephony")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}
Returns a {{domxref("Telephony")}} object you can use to create and manage telephone calls.
{{domxref("window.navigator.product", "navigator.product")}} {{non-standard_inline}}
Returns the product name of the current browser. (e.g. "Gecko")
{{domxref("window.navigator.productSub", "navigator.productSub")}} {{non-standard_inline}}
Returns the build number of the current browser (e.g. "20060909")
{{domxref("window.navigator.securitypolicy", "navigator.securitypolicy")}} {{non-standard_inline}}
Returns an empty string. In Netscape 4.7x, returns "US & CA domestic policy" or "Export policy".
{{domxref("window.navigator.standalone", "navigator.standalone")}} {{non-standard_inline}}
Returns a boolean indicating whether the browser is running in standalone mode. Available on Apple's iOS Safari only.
{{domxref("window.navigator.vendor", "navigator.vendor")}} {{non-standard_inline}}
Returns the vendor name of the current browser (e.g. "Netscape6")
{{domxref("window.navigator.vendorSub", "navigator.vendorSub")}} {{non-standard_inline}}
Returns the vendor version number (e.g. "6.1")
navigator.webkitPointer {{non-standard_inline}}
Returns a PointerLock object for the Mouse Lock API.

Methods

Standard

{{domxref("window.navigator.javaEnabled", "navigator.javaEnabled")}}
Indicates whether the host browser is Java-enabled or not.
{{domxref("window.navigator.registerContentHandler", "navigator.registerContentHandler")}}
Allows web sites to register themselves as a possible handler for a given MIME type.
{{domxref("navigator.registerProtocolHandler", "navigator.registerProtocolHandler")}}
Allows web sites to register themselves as a possible handler for a given protocol.
{{domxref("window.navigator.vibrate", "navigator.vibrate()")}} {{gecko_minversion_inline("11.0")}}
Causes vibration on devices with support for it. Does nothing if vibration support isn't available.

Non standard

{{domxref("window.navigator.addIdleObserver", "navigator.addIdleObserver")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}
Allows to add an observer to check when the user is idle.
{{domxref("window.navigator.mozHasPendingMessage", "navigator.mozHasPendingMessage")}} {{non-standard_inline}} {{b2g_required_inline("1.0")}}
Allows an app to know if there is a pending message of a given type.
{{domxref("window.navigator.mozIsLocallyAvailable", "navigator.mozIsLocallyAvailable")}} {{non-standard_inline}}
Lets code check to see if the document at a given URI is available without using the network.
{{domxref("window.navigator.mozSetMessageHandler", "navigator.mozSetMessageHandler")}} {{non-standard_inline}} {{b2g_required_inline("1.0")}}
Allows an app to register a function handler for any kind of system message.
{{domxref("window.navigator.preference", "navigator.preference")}} {{obsolete_inline("2.0")}} {{non-standard_inline}}
Sets a user preference. This method is only available to privileged code and is obsolete; you should use the XPCOM Preferences API instead.
{{domxref("window.navigator.removeIdleObserver", "navigator.removeIdleObserver")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}
Allows to remove an observer used to check if the user is idle.
{{domxref("window.navigator.requestWakeLock", "navigator.requestWakeLock")}} {{non-standard_inline}}
Request a wake lock for a resource. A wake lock prevents a specific part of a device from being turned off automatically.
{{domxref("window.navigator.taintEnabled", "navigator.taintEnabled")}} {{deprecated_inline("1.7.8")}} {{obsolete_inline("9.0")}} {{non-standard_inline}}
Returns false. JavaScript taint/untaint functions removed in JavaScript 1.2.

Examples

Example #1: Browser detect and return a string

var sBrowser, sUsrAg = navigator.userAgent;

if(sUsrAg.indexOf("Chrome") > -1) {
    sBrowser = "Google Chrome";
} else if (sUsrAg.indexOf("Safari") > -1) {
    sBrowser = "Apple Safari";
} else if (sUsrAg.indexOf("Opera") > -1) {
    sBrowser = "Opera";
} else if (sUsrAg.indexOf("Firefox") > -1) {
    sBrowser = "Mozilla Firefox";
} else if (sUsrAg.indexOf("MSIE") > -1) {
    sBrowser = "Microsoft Internet Explorer";
}

alert("You are using: " + sBrowser);

Example #2: Browser detect and return an index

function getBrowserId () {

    var
        aKeys = ["MSIE", "Firefox", "Safari", "Chrome", "Opera"],
        sUsrAg = navigator.userAgent, nIdx = aKeys.length - 1;

    for (nIdx; nIdx > -1 && sUsrAg.indexOf(aKeys[nIdx]) === -1; nIdx--);

    return nIdx

}

console.log(getBrowserId());

Specification

  • {{SpecName("HTML5 W3C", "webappapis.html#the-navigator-object","window.navigator")}}
  • {{SpecName("HTML5.1", "webappapis.html#the-navigator-object", "window.navigator")}}
  • {{SpecName("HTML WHATWG", "timers.html#the-navigator-object", "window.navigator")}}

See also

Revision Source

<div>
  {{DomRef}}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<p>Returns a reference to the navigator object, which can be queried for information about the application running the script.</p>
<h2 id="Example" name="Example">Example</h2>
<div style="overflow:hidden">
  <pre class="brush:js">
alert("You're using " + navigator.appName);
</pre>
</div>
<h2 id="Properties" name="Properties">Properties</h2>
<h3 id="Standard">Standard</h3>
<dl>
  <dt>
    {{domxref("window.navigator.appName", "navigator.appName")}}</dt>
  <dd>
    Returns the official name of the browser. Do not rely on this property to return the correct value.</dd>
  <dt>
    {{domxref("window.navigator.appVersion", "navigator.appVersion")}}</dt>
  <dd>
    Returns the version of the browser as a string. Do not rely on this property to return the correct value.</dd>
  <dt>
    {{domxref("window.navigator.battery", "navigator.battery")}} {{gecko_minversion_inline("10.0")}}</dt>
  <dd>
    Returns a {{domxref("window.navigator.battery", "battery")}} object you can use to get information about the battery charging status.</dd>
  <dt>
    {{domxref("window.navigator.connection", "navigator.connection")}}</dt>
  <dd>
    Provides information about the network connection of a device.</dd>
  <dt>
    {{domxref("window.navigator.cookieEnabled", "navigator.cookieEnabled")}}</dt>
  <dd>
    Returns a boolean indicating whether cookies are enabled in the browser or not.</dd>
  <dt>
    {{domxref("window.navigator.language", "navigator.language")}}</dt>
  <dd>
    Returns a string representing the language version of the browser.</dd>
  <dt>
    {{domxref("window.navigator.mimeTypes", "navigator.mimeTypes")}}</dt>
  <dd>
    Returns a list of the MIME types supported by the browser.</dd>
  <dt>
    {{domxref("window.navigator.onLine", "navigator.onLine")}}</dt>
  <dd>
    Returns a boolean indicating whether the browser is working online.</dd>
  <dt>
    {{domxref("window.navigator.oscpu", "navigator.oscpu")}}</dt>
  <dd>
    Returns a string that represents the current operating system.</dd>
  <dt>
    {{domxref("window.navigator.platform", "navigator.platform")}}</dt>
  <dd>
    Returns a string representing the platform of the browser.</dd>
  <dt>
    {{domxref("window.navigator.plugins", "navigator.plugins")}}</dt>
  <dd>
    Returns an array of the plugins installed in the browser.</dd>
  <dt>
    {{domxref("window.navigator.userAgent", "navigator.userAgent")}}</dt>
  <dd>
    Returns the user agent string for the current browser.</dd>
</dl>
<h3 id="Methods" name="Methods">Non standard</h3>
<dl>
  <dt>
    {{domxref("window.navigator.appCodeName", "navigator.appCodeName")}} {{non-standard_inline}}</dt>
  <dd>
    Returns the internal "code" name of the current browser. Do not rely on this property to return the correct value.</dd>
  <dt>
    {{domxref("window.navigator.buildID", "navigator.buildID")}} {{non-standard_inline}}</dt>
  <dd>
    Returns the build identifier of the browser (e.g. "2006090803")</dd>
  <dt>
    {{domxref("navigator.doNotTrack")}} {{non-standard_inline}}</dt>
  <dd>
    Reports the value of the user's do-not-track preference. When this value is "yes", your web site or application should not track the user.</dd>
  <dt>
    {{domxref("navigator.id")}} {{non-standard_inline}}</dt>
  <dd>
    Returns the {{domxref("window.navigator.id", "id")}} object which you can use to add support for <a href="/en-US/docs/BrowserID" title="BrowserID">BrowserID</a> to your web site.</dd>
  <dt>
    {{domxref("window.navigator.mozAlarms","navigator.mozAlarms")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}</dt>
  <dd>
    Returns a {{domxref("MozAlarmsManager", "MozAlarmsManager")}} object you can use to schedule notifications or applications to be started at a specific time.</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("window.navigator.mozCameras", "navigator.mozCameras")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}</dt>
  <dd>
    Return a {{domxref("CameraManager")}} object you can use to access cameras available on your device.</dd>
  <dt>
    {{domxref("navigator.mozMobileConnection")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}</dt>
  <dd>
    Return a <code>MozMobileConnection</code> object to retrieve the connection states of a mobile device and to perform some SIM/RUIM card actions.</dd>
  <dt>
    {{domxref("navigator.mozNotification")}} {{MobileOnlyInline("2.0")}} {{non-standard_inline}}<br />
    {{domxref("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("window.navigator.mozPower", "navigator.mozPower")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}</dt>
  <dd>
    Returns a {{domxref("PowerManager")}} object that allow to control the power usage and turn off unused peripherals to save power.</dd>
  <dt>
    {{domxref("window.navigator.mozSettings", "navigator.mozSettings")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}</dt>
  <dd>
    Returns a {{domxref("SettingsManager")}} object you can use to access the device's settings</dd>
  <dt>
    {{domxref("window.navigator.mozSms", "navigator.mozSms")}} {{b2g_required_inline("1.0")}} {{gecko_minversion_inline("12.0")}} {{non-standard_inline}}</dt>
  <dd>
    Returns a {{domxref("SmsManager")}} object you can use to manage SMS messaging in your web application.</dd>
  <dt>
    {{domxref("navigator.mozSocial")}} {{non-standard_inline}}</dt>
  <dd>
    {{todo("NeedsText")}}</dd>
  <dt>
    {{domxref("window.navigator.mozTelephony", "navigator.mozTelephony")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}</dt>
  <dd>
    Returns a {{domxref("Telephony")}} object you can use to create and manage telephone calls.</dd>
  <dt>
    {{domxref("window.navigator.product", "navigator.product")}} {{non-standard_inline}}</dt>
  <dd>
    Returns the product name of the current browser. (e.g. "Gecko")</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 &amp; 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>
    Returns the vendor name of the current browser (e.g. "Netscape6")</dd>
  <dt>
    {{domxref("window.navigator.vendorSub", "navigator.vendorSub")}} {{non-standard_inline}}</dt>
  <dd>
    Returns the vendor version number (e.g. "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">Methods</h2>
<h3 id="Standard">Standard</h3>
<dl>
  <dt>
    {{domxref("window.navigator.javaEnabled", "navigator.javaEnabled")}}</dt>
  <dd>
    Indicates whether the host browser is Java-enabled or not.</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("window.navigator.vibrate", "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">Non standard</h3>
<dl>
  <dt>
    {{domxref("window.navigator.addIdleObserver", "navigator.addIdleObserver")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}</dt>
  <dd>
    Allows to add an observer to check when the user is idle.</dd>
  <dt>
    {{domxref("window.navigator.mozHasPendingMessage", "navigator.mozHasPendingMessage")}} {{non-standard_inline}} {{b2g_required_inline("1.0")}}</dt>
  <dd>
    Allows an app to know if there is a pending message of a given type.</dd>
  <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.mozSetMessageHandler", "navigator.mozSetMessageHandler")}} {{non-standard_inline}} {{b2g_required_inline("1.0")}}</dt>
  <dd>
    Allows an app to register a function handler for any kind of system message.</dd>
  <dt>
    {{domxref("window.navigator.preference", "navigator.preference")}} {{obsolete_inline("2.0")}} {{non-standard_inline}}</dt>
  <dd>
    Sets a user preference. This method is <a class="external" href="http://www.faqts.com/knowledge_base/view.phtml/aid/1608/fid/125/lang/en">only available to privileged code</a> and is obsolete; you should use the XPCOM <a href="/en-US/docs/Preferences_API" title="Preferences_API">Preferences API</a> instead.</dd>
  <dt>
    {{domxref("window.navigator.removeIdleObserver", "navigator.removeIdleObserver")}} {{b2g_required_inline("1.0")}} {{non-standard_inline}}</dt>
  <dd>
    Allows to remove an observer used to check if the user is idle.</dd>
  <dt>
    {{domxref("window.navigator.requestWakeLock", "navigator.requestWakeLock")}} {{non-standard_inline}}</dt>
  <dd>
    Request a wake lock for a resource. A wake lock prevents a specific part of a device from being turned off automatically.</dd>
  <dt>
    {{domxref("window.navigator.taintEnabled", "navigator.taintEnabled")}} {{deprecated_inline("1.7.8")}} {{obsolete_inline("9.0")}} {{non-standard_inline}}</dt>
  <dd>
    Returns <code>false</code>. JavaScript taint/untaint functions removed in JavaScript 1.2.</dd>
</dl>
<h2 id="Specification" name="Specification">Examples</h2>
<h3 id="Example_.231.3A_Browser_detect_and_return_a_string">Example #1: Browser detect and return a string</h3>
<pre class="brush: js">
var sBrowser, sUsrAg = navigator.userAgent;

if(sUsrAg.indexOf("Chrome") &gt; -1) {
&nbsp;&nbsp; &nbsp;sBrowser = "Google Chrome";
} else if (sUsrAg.indexOf("Safari") &gt; -1) {
&nbsp;&nbsp; &nbsp;sBrowser = "Apple Safari";
} else if (sUsrAg.indexOf("Opera") &gt; -1) {
&nbsp;&nbsp; &nbsp;sBrowser = "Opera";
} else if (sUsrAg.indexOf("Firefox") &gt; -1) {
&nbsp;&nbsp; &nbsp;sBrowser = "Mozilla Firefox";
} else if (sUsrAg.indexOf("MSIE") &gt; -1) {
&nbsp;&nbsp; &nbsp;sBrowser = "Microsoft Internet Explorer";
}

alert("You are using: " + sBrowser);</pre>
<h3 id="Example_.232.3A_Browser_detect_and_return_an_index">Example #2: Browser detect and return an index</h3>
<pre class="brush: js">
function getBrowserId () {

&nbsp;&nbsp; &nbsp;var
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;aKeys = ["MSIE", "Firefox", "Safari", "Chrome", "Opera"],
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sUsrAg = navigator.userAgent, nIdx = aKeys.length - 1;

&nbsp;&nbsp; &nbsp;for (nIdx; nIdx &gt; -1 &amp;&amp; sUsrAg.indexOf(aKeys[nIdx]) === -1; nIdx--);

&nbsp;&nbsp; &nbsp;return nIdx

}

console.log(getBrowserId());</pre>
<h2 id="Specification" name="Specification">Specification</h2>
<ul>
  <li>{{SpecName("HTML5 W3C", "webappapis.html#the-navigator-object","window.navigator")}}</li>
  <li>{{SpecName("HTML5.1", "webappapis.html#the-navigator-object", "window.navigator")}}</li>
  <li>{{SpecName("HTML WHATWG", "timers.html#the-navigator-object", "window.navigator")}}</li>
</ul>
<h2 id="See_also" name="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/DOM_Client_Object_Cross-Reference/navigator" title="DOM_Client_Object_Cross-Reference/navigator">DOM Client Object Cross-Reference:navigator</a></li>
</ul>
Revert to this revision