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

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.