Home > Back-end >  Downloading files in browser window after opening in Javascript?
Downloading files in browser window after opening in Javascript?

Time:04-07

Im trying to open a browser in Javascript and use that browser to download a file. I am doing this in a Microsoft Excel Add-in. The reason is because on MacOS on the desktop version of Excel, you cannot currently download files to the desktop via the addin.

According to the team, the workaround is to use: Office.context.ui.openBrowserWindow(url) to open the url and download the file once the browser is open.

But how do I download the file once its open? Ive tried doing something like:

Office.context.ui.openBrowserWindow("https://google.com", function() {
  const bl = new Blob([JSON.stringify(data, null, 2)], {type: "application/json"});
  const a = document.createElement("a");
  a.href = URL.createObjectURL(bl);
  a.download = "test.json";
  document.body.appendChild(a);
  a.click();
})

but im getting nothing working.

Any advice?

CodePudding user response:

openBrowserWindow doesn't take a second parameter.

I think the workaround is that you create a page on your add-in domain that has a UI for downloading the file. Then you use openBrowserWindow to open that page.

  • Related