The navigator
obiect belongs to the "window" object.
- navigator
contains information about the browser application.
This object has some properties and methods that can be used with syntax:
cookieEnabled
- returns True if cookie is enabled in browser, otherwise, False.
var msg = (navigator.cookieEnabled) ? 'Cookie can be used in browser' :'Ccookie cannot be used in browser'; document.write('<p>'+ msg +'</p>');
geolocation
- returns a Geolocation
object that can be used to locate the user's position (it works in pages with 'secure' address: HTTPS).
<p id='prg1'>Click on the button to get the coords of your geolocation.</p> <button onclick='getLocation()'>Get coords</button> <script> var prg1 = document.getElementById('prg1'); //called from button function getLocation(){ var options = { enableHighAccuracy: true, timeout: 5000}; var error =(err)=>{ prg1.innerHTML ='ERROR: '+ err.code +' - '+err.message; } if(navigator.geolocation) navigator.geolocation.getCurrentPosition(showPosition, error, options); else prg1.innerHTML ='Geolocation is not enabled in this browser.'; } function showPosition(pos){ prg1.innerHTML = 'Latitude: '+ pos.coords.latitude +'<br>Longitude: '+ pos.coords.longitude; } </script>
language
- the language set in browser.
document.write('<p>The language set in browser: '+ navigator.language +'</p>'); //Ex.: en-US
onLine
- returns True if the browser is online, otherwise False.
document.write('<p>The browser is online: '+ navigator.onLine +'</p>');
oscpu
- returns a string with the current operation system, or 'undefined'.
document.write('<p>The used operation system:<br> '+ navigator.oscpu +'</p>'); //ex.: Windows NT 6.1
userAgent
- returns a string with the user-agent header sent by the browser to the server.
document.write('<p>location.userAgent returned:<br> '+ navigator.userAgent +'</p>'); //ex.: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.87 Safari/537.36
navigator
object is:
vibrate(ms)
- causes vibration on devices with support for it. Does nothing if vibration support isn't available.
<img src="image.jpg" usemap="#map1"> <map name="map1"> <area shape="rect" coords="9, 120, 56, 149" href="#"> <area shape="rect" coords="100, 200, 156, 249" href="#"> </map>
#id { overflow: auto; }
document.getElementById("id").onmouseover = function(){ document.write("Have Good Life"); }
if(isset($_GET["id"])) { echo $_GET["id"]; }