codegoboom
04-04-2005, 01:16 PM
// ActiveX nullifier
function AXO(progId,loc){
if(!(progId instanceof Array))
return bind(progId);
function bind(pId){
try{
throw loc ? new ActiveXObject(pId,loc) : new ActiveXObject(pId);}
catch(obj){
return obj instanceof Error ? null : obj;}}
var retval, p, i = -1;
while(p = progId[++i])
if(retval = bind(p))
break;
return retval;}
Just a simple alternative to standard JScript syntax: new ActiveXObject (http://msdn.microsoft.com/library/en-us/script56/html/js56jsobjactivexobject.asp)(servername.typename[, location])
The function AXO(servername.typename[, location]) returns an automation object or null--as opposed to the usual error generated...
It also allows for an array of [servername.typename]s, such as:
function(){
var iDom = ["Msxml2.DOMDocument.4.0",
"Msxml2.DOMDocument",
"Microsoft.XMLDOM"];
var iHttp = ["Msxml2.XMLHTTP.4.0",
"Msxml2.XMLHTTP",
"Microsoft.XMLHTTP",
"WinHttp.WinHttpRequest.5.1"];
var iFb;
if(!(iDom = AXO(iDom)) || !(iHttp = AXO(iHttp)) || !(iFb = AXO("Foo.Bar")))
// return... one of three is null
// onward...}
Applies to JScript version (http://msdn.microsoft.com/library/en-us/script56/html/js56jsoriversioninformation.asp) 5.0 +
function AXO(progId,loc){
if(!(progId instanceof Array))
return bind(progId);
function bind(pId){
try{
throw loc ? new ActiveXObject(pId,loc) : new ActiveXObject(pId);}
catch(obj){
return obj instanceof Error ? null : obj;}}
var retval, p, i = -1;
while(p = progId[++i])
if(retval = bind(p))
break;
return retval;}
Just a simple alternative to standard JScript syntax: new ActiveXObject (http://msdn.microsoft.com/library/en-us/script56/html/js56jsobjactivexobject.asp)(servername.typename[, location])
The function AXO(servername.typename[, location]) returns an automation object or null--as opposed to the usual error generated...
It also allows for an array of [servername.typename]s, such as:
function(){
var iDom = ["Msxml2.DOMDocument.4.0",
"Msxml2.DOMDocument",
"Microsoft.XMLDOM"];
var iHttp = ["Msxml2.XMLHTTP.4.0",
"Msxml2.XMLHTTP",
"Microsoft.XMLHTTP",
"WinHttp.WinHttpRequest.5.1"];
var iFb;
if(!(iDom = AXO(iDom)) || !(iHttp = AXO(iHttp)) || !(iFb = AXO("Foo.Bar")))
// return... one of three is null
// onward...}
Applies to JScript version (http://msdn.microsoft.com/library/en-us/script56/html/js56jsoriversioninformation.asp) 5.0 +