JavaScript

Calling a function of the opener window

It is possible, using JavaScript, to call a function pertaining to the opener window, that is the window that, calling window.open, opened the current window. The code to use is the following: if (window.opener) { window.close(); window.opener.foo("bar"); } First it checks if the opener window is still open. In this case, it closes the current window and call the foo function on the opener window.

Creating a Class definition in JavaScript

There are different ways to define classes in JavaScript. However, this is the most widely used and accepted at the moment: //class function Person(sLastName, sFirstName, iAge) { this.lastName = sLastName; this.firstName = sFirstName; this.age = iAge; this.phoneNumbers = new Array(); } //method Person.prototype.showFullName = function() { alert(this.lastName + " " + this.firstName); }; //instances var oPerson1 = new Person("Lacava", "Alessandro", 30); var oPerson2 = new Person("Brown", "John", 50); oPerson1.phoneNumbers.push("1234567"); oPerson2.phoneNumbers.push("7654321"); oPerson1.

Creating an instance of the object used to make AJAX calls

Nowadays, AJAX is a ubiquitous technology in the IT world. When you need to create the object used to send asynchronous requests to a server, you might face the browser-difference problem. Here is a JavaScript function you could use to overcome this problem: // The following function creates an XMLHttpRequest object function createHttpRequest() { if (typeof XMLHttpRequest != "undefined") //NOT IE { return new XMLHttpRequest(); } else if (window.ActiveXObject) // IE { var sVersions = [ "MSXML2.