Objektet window.navigator
indeholder oplysninger om besøgendes browser.
Objektet window.navigator
kan skrives uden vinduespræfikset.
Nogle eksempler:
navigator.cookieEnabled
navigator.appCodeName
navigator.platform
Egenskaben cookieEnabled
returnerer true, hvis cookies er aktiveret, ellers falsk:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"cookiesEnabled is " + navigator.cookieEnabled;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The cookieEnabled property returns true if cookies are enabled:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.cookieEnabled is " + navigator.cookieEnabled;
</script>
</body>
</html>
Egenskaben appName
returnerer applikationsnavnet af browseren:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.appName is " + navigator.appName;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The appName property returns the application name of the browser:</p>
<p id="demo"></p>
<p>Strange enough, "Netscape" is the application name for IE11, Chrome, Firefox, and Safari.</p>
<script>
document.getElementById("demo").innerHTML =
"navigator.appName is " + navigator.appName;
</script>
</body>
</html>
Denne ejendom er fjernet (forældet) i den seneste webstandard.
De fleste browsere (IE11, Chrome, Firefox, Safari) returnerer Netscape som appName.
Egenskaben appCodeName
returnerer applikationskodenavnet af browseren:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.appCodeName is " + navigator.appCodeName;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Navigator</h2>
<p>The appCodeName property returns the code name of the browser.</p>
<p>Do not rely on it! "Mozilla" is the application code name for Chrome, Firefox, IE, Safari, and Opera.</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.appCodeName is " + navigator.appCodeName;
</script>
</body>
</html>
Denne ejendom er fjernet (forældet) i den seneste webstandard.
De fleste browsere (IE11, Chrome, Firefox, Safari, Opera) returnerer Mozilla som appCodeName.
Egenskaben product
returnerer produktnavnet på browsermotoren:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.product is " + navigator.product;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The product property returns the product name of the browser.</p>
<p>Do not rely on it! Most browsers returns "Gecko" as product name!</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.product is " + navigator.product;
</script>
</body>
</html>
Denne ejendom er fjernet (forældet) i den seneste webstandard.
De fleste browsere returnerer Gecko som produkt.
Egenskaben appVersion
returnerer versionsoplysninger om browseren:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.appVersion;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The appVersion property returns version information about the browser:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.appVersion;
</script>
</body>
</html>
Egenskaben userAgent
returnerer brugeragent-headeren sendt af browseren til serveren:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.userAgent;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The userAgent property returns the user-agent header sent by the browser to the server:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
navigator.userAgent;
</script>
</body>
</html>
Oplysningerne fra navigatorobjektet kan ofte være vildledende.
Navigatorobjektet bør ikke bruges til at finde browserversioner, fordi:
Forskellige browsere kan bruge det samme navn
Navigatordataene kan ændres af browserens ejer
Nogle browsere fejlidentificerer sig selv for at omgå sitetests
Browsere kan ikke rapportere nye operativsystemer, der er udgivet senere end browseren
Egenskaben platform
returnerer browserplatformen (operativ system):
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.platform;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The platform property returns the browser platform (operating system):</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.platform is " + navigator.platform;
</script>
</body>
</html>
Egenskaben language
returnerer browserens sprog:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.language;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The language property returns the browser's language:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.language is " + navigator.language;
</script>
</body>
</html>
Egenskaben onLine
returnerer true, hvis browseren er online:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.onLine;
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The onLine property returns true if the browser is online:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"navigator.onLine is " + navigator.onLine;
</script>
</body>
</html>
Metoden javaEnabled()
returnerer true, hvis Java er aktiveret:
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = navigator.javaEnabled();
</script>
Prøv det selv →
<!DOCTYPE html>
<html>
<body>
<h2>The Navigator Object</h2>
<p>The javaEnabled() method returns true if Java is enabled:</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"javaEnabled is " + navigator.javaEnabled();
</script>
</body>
</html>