Add initial project files
This commit is contained in:
+22
@@ -0,0 +1,22 @@
|
||||
/// <reference lib="dom" />
|
||||
|
||||
/**
|
||||
* Downloads a file by providing a link.
|
||||
* @param href - The URL of the file to download.
|
||||
* @param name - The name of the downloaded file. Default is "file".
|
||||
* @param target - The target window or frame for the downloaded file. Default is "_blank".
|
||||
* @example
|
||||
* // Example usage:
|
||||
* downloadFileByLink("https://example.com/file.pdf", "myFile", "_self");
|
||||
*/
|
||||
export const downloadFileByLink = (href: string, name = 'file', target = '_blank'): void => {
|
||||
const link = document.createElement('a');
|
||||
link.href = href;
|
||||
link.download = name;
|
||||
link.target = target;
|
||||
link.style.visibility = 'hidden';
|
||||
link.setAttribute('target', '_blank');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
};
|
||||
Reference in New Issue
Block a user