In this lesson are presented the JavaScript level one browser objects: navigator and history.

1. navigator object

The navigator object gives some informations about what browser is running your code.
You can use it to collect data about what browsers visit your sites. For example, if you know that Internet Explorer doesn’t support some code, you can test:
      if ( window.navigator.appName == "Microsoft Internet Explorer" ).

navigator object properties


- The following example writes in the page the return values of these properties (used on Firefox).
<script type="text/javascript"><!--
document.write('appCodeName - '+ navigator.appCodeName+ '<br />');
document.write('appName - '+ navigator.appName+ '<br />');
document.write('appVersion - '+ navigator.appVersion+ '<br />');
document.write('cookieEnabled - '+ navigator.cookieEnabled+ '<br />');
document.write('platform - '+ navigator.platform+ '<br />');
document.write('userAgent - '+ navigator.userAgent+ '<br />');
--></script>
- The result is:
appCodeName - Mozilla
appName - Netscape
appVersion - 5.0 (Windows; en-US)
cookieEnabled - true
platform - Win32
userAgent - Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13

navigator object methods


- The following example writes a message about if Java is enabled or not.
<script type="text/javascript"><!--
if (navigator.javaEnabled) document.write('Java enabled');
else document.write('Java is not enabled');
--></script>

2. history object

The history object contains a list of URLs that the user visited within the current browser window and some features to navigate that list. It is part of the window object and is accessed through the window.history

history object properties

- Example:
<script type="text/javascript"><!--
document.write(window.history.length);      // 3
--></script>

history object methods


- The fallowing example creates a button to go back two pages:
<script type="text/javascript"><!--
function goBack() {
  window.history.go(-2);
}
--></script>
<button onclick="goBack()">Go Back 2</button>

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is used to add lists into <ul> and <ol> elements?
<dt> <dd> <li>
<ul>
 <li>http://coursesweb.net/html/</li>
 <li>http://coursesweb.net/css/</li>
</ul>
Which value of the "display" property creates a block box for the content and ads a bullet marker?
block list-item inline-block
.some_class {
  display: list-item;
}
Which instruction converts a JavaScript object into a JSON string.
JSON.parse() JSON.stringify eval()
var obj = {
 "courses": ["php", "javascript", "ajax"]
};
var jsonstr = JSON.stringify(obj);
alert(jsonstr);    // {"courses":["php","javascript","ajax"]}
Indicate the PHP class used to work with HTML and XML content in PHP.
stdClass PDO DOMDocument
$strhtml = '<body><div id="dv1">CoursesWeb.net</div></body>';
$dochtml = new DOMDocument();
$dochtml->loadHTML($strhtml);
$elm = $dochtml->getElementById("dv1");
echo $elm->nodeValue;    // CoursesWeb.net
navigator and history objects

Last accessed pages

  1. PHP OOP - Constructor Method (3127)
  2. SSEP - Site Search Engine PHP-Ajax (4261)
  3. Super Dragon Mahjongg (534)
  4. The Rise Of Atlantis (94)
  5. Butterfly Kyodai (1172)

Top accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (45775)
  2. Read Excel file data in PHP - PhpExcelReader (34434)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (34319)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (30908)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (28149)