De hecho, puede anular ActiveXObject()
.
Esto significa que puede tratar de crear un objeto proxy transparente alrededor del objeto real y enganchar las llamadas al método. Esto significa que tendrías que construir un proxy alrededor de cada método y propiedad que tenga tu objeto ActiveX, a menos que estés absolutamente seguro de que no hay un código que llame a un método o propiedad en particular.
He creado una pequeña envoltura para el objeto "MSXML2.XMLHTTP"
. Probablemente hay todo tipo de problemas que se pueden ejecutar en, por lo que tomar con un grano de sal:
var ActualActiveXObject = ActiveXObject;
var ActiveXObject = function(progid) {
var ax = new ActualActiveXObject(progid);
if (progid.toLowerCase() == "msxml2.xmlhttp") {
var o = {
_ax: ax,
_status: "fake",
responseText: "",
responseXml: null,
readyState: 0,
status: 0,
statusText: 0,
onReadyStateChange: null
// add the other properties...
};
o._onReadyStateChange = function() {
var self = o;
return function() {
self.readyState = self._ax.readyState;
self.responseText = self._ax.responseText;
self.responseXml = self._ax.responseXml;
self.status = self._ax.status;
self.statusText = self._ax.statusText;
if (self.onReadyStateChange) self.onReadyStateChange();
}
}();
o.open = function(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword) {
varAsync = (varAsync !== false);
this._ax.onReadyStateChange = this._onReadyStateChange
return this._ax.open(bstrMethod, bstrUrl, varAsync, bstrUser, bstrPassword);
};
o.send = function(varBody) {
return this._ax.send(varBody);
};
// add the other methods...
}
else {
var o = ax;
}
return o;
}
function Test() {
var r = new ActiveXObject('Msxml2.XMLHTTP');
alert(r._status); // "fake"
r.onReadyStateChange = function() { alert(this.readyState); };
r.open("GET", "z.xml");
r.send();
alert(r.responseText);
}
responsabilidad: Especialmente el manejo asíncrono/onreadystatechange probablemente no está bien, y el código puede tener otros problemas como bien. Como dije, es solo una idea. Tratar con cuidado.
P.S .: Un objeto COM distingue entre mayúsculas y minúsculas cuando se trata de nombres de métodos y propiedades. Este contenedor es (como todo JavaScript) sensible a mayúsculas y minúsculas. Por ejemplo, si su código pasa a llamar tanto "Send()"
y "send()"
, se necesita un esqueleto "Send()" método de la envoltura, así:
o.Send = function() { return this.send.apply(this, arguments); };
no creo que esto va a posible. ¿Tiene fuente para el Tconnetor? ¿Puedes redistribuir los binarios a los clientes y/o distribuir tus propios binarios si no eres el propietario? – AnthonyWJones
No tengo la fuente, pero sí tengo una licencia que me permite redistribuirla libremente. De cualquier manera, ¿por qué todo esto importa si hago un objeto javascript proxy para llamadas proxy al objeto activeX? – mkoryak
@mkoryak: He limpiado/actualizado el código en mi respuesta, y he creado una respuesta de enlace en su otra pregunta. – Tomalak