Categories
JavaScript Answers

How to set a file name using window.open with JavaScript?

Spread the love

Sometimes, we want to set a file name using window.open with JavaScript.

In this article, we’ll look at how to set a file name using window.open with JavaScript.

How to set a file name using window.open with JavaScript?

To set a file name using window.open with JavaScript, we use the download attribute on the link.

For instance, we write

<a href="foo.txt" download="your-foo.txt">Download Your Foo</a>

to set the download attribute to the name of the file we want to download.

The href attribute to the URL of the file.

Conclusion

To set a file name using window.open with JavaScript, we use the download attribute on the link.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *