Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Business Requirements is that downloads do not trigger a new tab to open. #797

Open
bigbigDreamer opened this issue Aug 3, 2023 · 2 comments

Comments

@bigbigDreamer
Copy link

When I download a signed download link, it will open a new tab and then quickly close it before downloading. I find it strange. Is there any way to trigger the download in the current tab?

I have to use the following code for substitution:

const a = document.createElement('a');
    a.href = res?.DomainObj;
    a.download = fileName;
    a.click();

Is there any configuration that can be operated?

@bigbigDreamer bigbigDreamer changed the title My request is that downloads do not trigger a new tab to open. My Business Requirements is that downloads do not trigger a new tab to open. Aug 3, 2023
@ruimcf
Copy link

ruimcf commented Jan 8, 2024

I have the exact same doubt. I also replaced FileSaver.js with direct a[download] that does not trigger a new tab:

   const downloadLink = document.createElement('a');

    downloadLink.href = downloadUrl;
    document.body.appendChild(downloadLink);
    downloadLink.click();
    document.body.removeChild(downloadLink);

Looking at the source code it, when CORS is not enabled and adds a.target = '_blank' https://github.com/eligrey/FileSaver.js/blob/master/src/FileSaver.js#L99 is there a specific reason for it?

@ZachHaber
Copy link

If the download fails and you aren't using a.target = '_blank', then your webpage will be replaced by the error page, if you do it in a new tab, then the new tab is the one with the error page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants