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.
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 {
returnnew XMLHttpRequest();
}
elseif (window.ActiveXObject) // IE {
var sVersions = [ "MSXML2.XMLHttp.5.0",
"MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
"MSXML2.XMLHttp","Microsoft.XMLHttp" ];
//try to get an instance of the newer version.
//If it is not available go down till the oldest one
for (var i = 0; i < sVersions.length; i++) {
try {
var ret = new ActiveXObject(sVersions[i]);
return ret;
}
catch (oException) {
//Do nothing. Just go on trying with the older versions
}
}
}
//if it gets here then no version is available
alert("XMLHttpRequest object could not be created.");
}
As you can see this function creates the correct instance of the XMLHttpRequest object. If the browser is not
Internet Explorer then it just instantiates the XMLHttpRequest object, otherwise it tries to create the correct
ActiveX object used by IE to represent XMLHttpRequest. In this case it tries to instatiates the object from the
newer version going down till the oldest one.