How to deploy an ActiveX control through JavaScript/jQuery DOM methods?
I have a page that needs to be able to invoke the installation of an ActiveX control through JavaScript. I have tried a few DOM-centric methods, but have not been able to get anywhere. If the ActiveX is already installed, I can get it to load, but I can't seem to get the CAB to install. Using straight HTML, the installation works, yellow bar and all.
This is the code that is able to load the ActiveX. It uses jQuery 1.4.2. host is a reference to a visible div element on the page. result is true if the ActiveX is loaded, false othe开发者_如何学运维rwise (I don't know if it works on all ActiveX controls, but it works for the one my company has developed).
var attributes = {
id: "ax",
classid: "clsid:" + drv.clsid,
codebase: install ? drv.cab : undefined,
width: 0,
height: 0
};
try {
axSelector = $("<object></object>", attributes);
host.append(axSelector);
} catch (e) {
return false;
}
ax = axSelector[0];
var result = ax && ax["Enabled"] !== undefined && ax["Enabled"] !== null;
axSelector.remove();
I got this working by refactoring my code so that I could embed the object tag into the page on the server side during a postback (ASP.NET). Not exactly the solution I was hoping for, but it works.
精彩评论