0
votes

We are migrating from IE 8 to Edge browser,

Below is the code working in IE 8, to load one file, but not in Edge.

if(window.ActiveXObject){
                var fso = new ActiveXObject("Scripting.FileSystemObject");
                var filepath = document.getElementById('filePath').value;
                var thefile = fso.getFile(filepath);

Could you please let me know equivalent code for edge browser.

2
AFAIK Microsoft dropped ActiveXjabaa
Trying to upload a file without using the browser to choose it via user interaction is IMHO not possible due to security reasons.Onki Hara
Is there an "else" section to your code snippet? Legacy code often includes a fallback for non-IE browsers which lack ActiveX which even back in the (bad) old days of IE-8 was a problem.Yogi

2 Answers

0
votes

Edge doesn't support ActiveX. You can use File API <input type="file"> to choose files and then use XMLHttpRequest to upload files in modern browsers.

For more information you can refer to this thread and this code sample.

0
votes

A lot has changed since the code you are trying to upgrade was created. Local Storage now exists and to download a file; (Use case somebody may need to save it for using it locally) a download attrib is added to the anchor html tag. The file needs to be made into a URL-Blob

<a id="download" download="example.png">
<button type="button" onClick="download()" class="UI">Download</button>
</a>
<script>
function download() {
   var download = document.getElementById("download");
   var image = document.getElementById("meme").toDataURL("image/png").replace("image/png", "image/octet-stream");
   download.setAttribute("href", image);
}
</script>

I would migrate to local-storage or IndexedDB API.

There is no drop in replacement for the activeX. because of security issues.

Major Differences

ActiveX allowed javascript to access a file to read or write, including being able to overwrite itself, anywhere on the hard drive.

HTML5 Allows reading and writting to localdata and several API for data including IndexDB. But file access is limited to what the user specifically uploads or for downloading into the download directory.

A Javascript WIKI page that replaces itself is no longer possible if you want it to overwrite itself. A Javascript WIKI page is possible using the IndexDB. Downloading the content is possible but limited for security reasons.