JavaScript ActiveXObject

2019-09-08 23:17发布

问题:

I have a queastion about ActiveXObject in javascript. I have tryed this code in Mozila FireFox 6.0.2

var AXobj = new ActiveXObject("WScript.Shell");
AXobj.SendKeys(key);

But the error console says that ActiveXObject is undefined. After that, I have tryed this:

var AXobj = new DOMParser("WScript.Shell");
AXobj.SendKeys(key);

But then, the error console says:

Error: uncaught exception: [Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "file:///C:/Documents%20and%20Settings/Guest/Desktop/stuff/html/GML%20to%20JS.html Line: 335"]

By the way, i don't want to use ActiveXObject only for SendKeys. I need it for more stuff (like writing in file... ) AND, the reason i use FireFox instead of IE is that FireFox supports HTML5.

回答1:

ActiveX is a proprietary technology only supported by Microsoft...

It will only work in IE (thank goodness).

It also has some serious security concerns which is a big reason it was never adopted by other browser providers.



回答2:

For this you can check if it is IE then do this otherwise do that.

Like:

Function exampleFunction()
{
if ($.browser.msie) { /* IE */
                //Your code

            else {
                //Your code
            }
}

just a suggestion.