ActiveXObject in Firefox or Chrome (not IE!)
ActiveX is only supported by IE - the other browsers use a plugin architecture called NPAPI. However, there's a cross-browser plugin framework called Firebreath that you might find useful.
ActiveXObject works in IE, but not in Firefox
You can't. ActiveX is an IE-only thing. If you need cross-browser support, you're gonna have to re-think what you're trying to do...
How To Run Active X Objects in Non-IE Browsers?
Here are some things to consider:
You should never do this
Seriously, never ever do this
No, really, I'm not kidding. One slight mistake in your security model, and you will be the internet pariah of the year. Do not do this.
If you're going to go ahead and do it anyway, you'll need an NPAPI plugin. Note that Chrome has announced that they will eventually be dropping support for NPAPI -- we don't know how soon, and given that they haven't provided adequate solutions for a large number of problems currently solved by plugins I'm hoping it's not in the next couple of months, but once they do you'll need to use Native Client on Chrome, and NPAPI on the other ones. For an NPAPI plugin you could look at FireBreath, which is a framework that allows you to create a plugin that works both as NPAPI and ActiveX
Any option that will allow you to do this will require the user to download and install something. There is no way around this, nor should there be.
Most web browsers run in user mode, i.e. not in administrator mode. Generally when not in administrator mode you have -- at best -- read only access to the System32 directory. If you need any better you'll have to launch another application that will request elevation and proxy commands to it from the plugin.
In short:
- This is a bad idea
- It's a pain in the neck
- It's really easy to make mistakes that would allow malicious attacks on users computers through your plugin.
- What you're talking about doing is really significantly more dangerous than I'm making it sound, but I don't know how to fully explain just how bad of an idea this would be.
What is the solution for reference error with javascript?
How to resolve this?
Check if the object exists before you try to use it. Perhaps something like this:
if (typeof(window.ActiveXObject) != "undefined") {
// your code
}
Also let me know if there a better way to have feature to copy files which is compatible on all browsers.
There isn't. Your code only works because the user has permitted a browser extension to allow it to work. Browsers which don't have that extension, or users which don't permit it, won't work. By default you can't control the file system from within the browser (for obvious security reasons).
Related Topics
When Does Js Interpret {} as an Empty Block Instead of an Empty Object
JavaScript - Cannot Set Property of Undefined
Recursive Matching with Regular Expressions in JavaScript
How to Overload Functions in JavaScript
Are Loops Really Faster in Reverse
Most Efficient Way to Concatenate Strings in JavaScript
How to Create a Dialog with "Ok" and "Cancel" Options
How Does the Math.Max.Apply() Work
How to Scroll to Specific Item Using Jquery
Axios Http Client - How to Construct Http Post Url with Form Params
Javascript: Which Browsers Support Parsing of Iso-8601 Date String with Date.Parse
Optional Chaining in JavaScript
How to 'Minify' JavaScript Code
Prototype Based VS. Class Based Inheritance
When and Why to 'Return False' in JavaScript