JavaScript Browser Properties

By | May 28, 2016

Originally published on May 25, 2016.

This post discusses some of the browser properties that can be found through JavaScript.

C = Google Chrome
S = Mozilla SeaMonkey 2.40

window
Property B Value
window.navigator S
navigator
Property B Value
navigator.userAgent CS
navigator.appName S
navigator.appCodeName S
navigator.appVersion S
navigator.buildID S
navigator.product S
navigator.productSub S
navigator.vendor S
navigator.vendorSub S
navigator.oscpu S
navigator.platform S
navigator.language S
navigator.languages S
navigator.doNotTrack S
navigator.cookieEnabled S
navigator.onLine S
navigator.battery S
navigator.mediaDevices S
navigator.geolocation S
navigator.mozApps S
navigator.mozContacts S
navigator.mimeTypes S
navigator.plugins S
navigator.getBattery S
navigator.vibrate S
navigator.javaEnabled S
navigator.getGamepads S
navigator.mozGetUserMedia S
navigator.sendBeacon S
navigator.registerProtocolHandler S
navigator.registerContentHandler S
navigator.taintEnabled S
screen
Property B Value
screen.width S
screen.height S
screen.availWidth S
screen.availHeight S
screen.top S
screen.left S
screen.availTop S
screen.availLeft S
screen.colorDepth S
screen.pixelDepth S
screen.mozOrientation S
screen.mozLockOrientation S
screen.mozUnlockOrientation S
location
Property B Value
location.href CS
location.hostname CS
location.pathname CS
location.protocol CS
Window Inner Width CS  pixels
Window Inner Height CS  pixels
window.innerHeight CS
document.documentElement.clientHeight CS
document.body.clientHeight CS
See also document.documentElement.clientHeight and window.innerHeight.
screen.colorDepth CS -bit
screen.pixelDepth CS -bit
screen.colorDepth CS -bit
document
Property B Value
document.lastModified CS
document.head
Property B Value
document.head.lang
document.head.title

Window Object

<script>// <![CDATA[
    document.write(window);
// ]]></script>
<script>// <![CDATA[ for (x in window) {     document.write("<b>" + x + " :</b> " + window[x].toSource() + "
"); } // ]]></script>

Navigator Object

It is not necessary to specify window before the navigator object. Either window.navigator and navigator will produce the same result.

<script>// <![CDATA[
    document.write(navigator);
// ]]></script>
<script>// <![CDATA[
for (x in navigator) {
    document.write("<b>" + x + " :</b> " + navigator[x].toSource() + "
"); } // ]]></script>

navigator.userAgent

It is not necessary to specify window before the navigator object. Either window.navigator and navigator will produce the same result.

123456789-123456789-123456789-123456789-123456789-123456789-123456789-123456789- ↩
<script>// <![CDATA[
    document.write(navigator.userAgent);
// ]]></script>

navigator.geolocation

getCurrentPosition : function getCurrentPosition() { [native code] }
watchPosition : function watchPosition() { [native code] }
clearWatch : function clearWatch() { [native code] }

<script>// <![CDATA[
if ("geolocation" in navigator) {
    /* Geolocation is available. */
    var latitude, longitude, accuracy;
    var options = {
        enableHighAccuracy: true,
        timeout: 5000,
        maximumAge: 0
    }
    for (x in navigator.geolocation) {
            document.write("<b>" + x + " :</b> "
                + navigator.geolocation[x] + "<br />");
    }
    function success(pos) {
        var crd = pos.coords;
        latitude = crd.latitude;
        longitude = crd.longitude;
        accuracy = crd.accuracy;
        var googleMapsLink = "http://maps.google.com/?q="
            + latitude + "," + longitude + "&t=k&z=20";
        document.getElementById("geolocation-demo").innerHTML =
            "It looks like you are at "
            + latitude + " "
            + longitude + ", ±"
            + accuracy + " meters.<br />See it on <a href=\""
            + googleMapsLink + "\" target=\"_blank\">Google Maps</a>.<br />";
    }
    function error(err) {
        document.getElementById("geolocation-demo").innerHTML =
            "ERROR(" + err.code + "): " + err.message + "<br />";
    }
    navigator.geolocation.getCurrentPosition(success, error, options);
} else {
    /* Geolocation is not available. */
    document.getElementById("geolocation-demo").innerHTML =
        "Geolocation is not available.<br />";
}
// ]]></script>
<p id="geolocation-demo"></p>

Screen Object

<script>// <![CDATA[
for (x in screen) {
    document.write("<b>" + x + " :</b> " + screen[x].toSource() + "
"); } // ]]></script>p

screen.width

screen.height

screen.availWidth

screen.availHeight

screen.top

screen.left

screen.availTop

screen.availLeft

screen.colorDepth

screen.pixelDepth

screen.mozOrientation

screen.mozLockOrientation()

screen.mozUnlockOrientation()

Location Object

History Object

Document Object

document.lastModified

<script>// <![CDATA[
    document.write(document.lastModified);
// ]]></script>

document.head Object

<script>// <![CDATA[
    document.write(document.head);
// ]]></script>

Dump of document.head Object

<script>// <![CDATA[
for (x in document.head) {
    document.write("<b>" + x + ":</b> " + document.head[x].toSource() + "<br />");
}
// ]]></script>


Leave a Reply