JAVASCRIPT- Scripting – CHAPTER 6

Selecting Elements By ID:  var section1 = document.getElementById(“section1″);

Selecting Elements by Name:  var radiobuttons = document.getElementsByName(“favorite_color”);

Selecting Elements by Type: var spans = document.getElementsByTagName(“span”);

 

JAVASCRIPT- Scripting – CHAPTER 6

JAVASCRIPT- The Window– CHAPTER 5

Properties: location — current URL

protocol

host

hostname

port

pathname

search

hash

Browser Information:

The Navigator object: properties – appName,appVersion,userAgent,platform

Browser sniffing using navigator.userAgent
// Define browser.name and browser.version for client sniffing, using code
// derived from jQuery 1.4.1. Both the name and number are strings, and both
// may differ from the public browser name and version. Detected names are:
//
// “webkit”: Safari or Chrome; version is WebKit build number
// “opera”: the Opera browser; version is the public version number
// “mozilla”: Firefox or other gecko-based browsers; version is Gecko version
// “msie”: IE; version is public version number
//
// Firefox 3.6, for example, returns: { name: “mozilla”, version: “1.9.2” }.
var browser = (function() {
var s = navigator.userAgent.toLowerCase();
var match = /(webkit)[ \/]([\w.]+)/.exec(s) ||
/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(s) ||
/(msie) ([\w.]+)/.exec(s) ||
!/compatible/.test(s) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(s) ||
[];

return { name: match[1] || “”, version: match[2] || “0” };
}());

The Screen Object

window.screen

Error Handling

window.onerror

JAVASCRIPT- The Window– CHAPTER 5

JavaScript- JavaScript in Web Browsers – Chapter 4

Synchronous, Asynchronous, and Deferred Scripts:

Defer:

<script src=“demo_defer.js” defer></script>

A script that will not run until after the page has loaded.

Async:

The script will be run async as soon as it is available.

JavaScript- JavaScript in Web Browsers – Chapter 4

JAVASCRIPT – Functions – CHAPTER 3

A function is a block of Javascript code that is defined once and called many numbers of times.

Defining Functions:

function callMe(index){

var a=index;

console.log(a);

}

callMe(5);//Invoking functions

//Object Literals

var o{

var a;

add:function(){

this.c=this.a+2;

}

};

o.add();

–Chapter 3 END

JAVASCRIPT – Functions – CHAPTER 3

JAVASCRIPT – Arrays – CHAPTER 2

An Array is a collection of values. Each value are accessed by index value.

Creating Arrays:

var empty = []; // An array with no elements
var primes = [2, 3, 5, 7, 11]; // An array with 5 numeric elements

Reading Arrays:

var a=[1,2,3];

a[0]//Read elememt 0.

–Chapter 2 END.

JAVASCRIPT – Arrays – CHAPTER 2

JavaScript – Object – Chapter 1

Object Literals:

var x={};

var point={x=0,y=0};

Creating Objects with new:

var js-new Object();

Prototype:

Every Javascript object has a second javascript object associated with it. The second object is known as prototype.

Object.prototype

Object.create():

That creates a new object.

var o1 = Object.create({x:1, y:2});// o1 inherits x and y

Inheritance

var o{

a:2,

m:function(){

return this.a+1;

}

};

var  p= Object.create(o);

p.a=10;

p.m();//will trace 11.

 JSON Serializing Objects:

ECMAScript 5 provides a method JSON.stringfy() and JSON.parser() to seralize and restore Javscript objects.

o = {x:1, y:{z:[false,null,””]}}; // Define a test object
s = JSON.stringify(o); // s is ‘{“x”:1,”y”:{“z”:[false,null,””]}}’
p = JSON.parse(s); // p is a deep copy of o

—Chapter 1 END.

JavaScript – Object – Chapter 1

Rich JavaScript Applications – the Seven Frameworks

http://blog.stevensanderson.com/2012/08/01/rich-javascript-applications-the-seven-frameworks-throne-of-js-2012/

Rich JavaScript Applications – the Seven Frameworks