How to create a url that opens a tab downloads a file and closes the tab

420
July 27, 2022, at 6:00 PM

I want to create an URL that when clicked upon opens a tab, downloads a file, and closes that tab. Do you guys know how to do it? Following is an example: https://cdn.discordapp.com/attachments/850262728428748830/937385812671209502/vineboom.ogg

I am quite new to this and overwhelmed to know where to start. Can somebody assist me with this? I tried messing with Anchor tag but that is not the answer. According to my research figured it has something to do with NodeJS and ExpressJS. Still no idea of what to do.

Answer 1

Create require variables as shown and then created a function with whatever name you like, here I am using "onLoad" as the name. This function just checks for the file name in the URL's file parameter specified then tries to find it in the server.

var url_string = window.location; //window.location.href
var url = new URL(url_string);
var file = url.searchParams.get("file");
var dFile = file;
function onLoad() {
    var hiddenElement = document.createElement('a');
hiddenElement.href = `${dFile}`;
hiddenElement.target = '_blank';
hiddenElement.download = `${dFile}`;
hiddenElement.click();
close()
}
Make sure to add onLoad function into the body with event listener of "onload"

<!DOCTYPE html>
<body onload="onLoad()">
</body>
Rent Charter Buses Company
READ ALSO
Waiting for download to complete on Puppeteer

Waiting for download to complete on Puppeteer

I have a script made using nodejs and puppeteer which downloads a file from a button (which doesn't redirect to a url), so right now i'm using await await page

366
Why is my signed XML getting rejected by authorization?

Why is my signed XML getting rejected by authorization?

I'm trying to create a signed XML post requestThe XML needs to be sent in the body of the request

207
What library can I use to generate random mock data based on Open API spec inside a node application?

What library can I use to generate random mock data based on Open API spec inside a node application?

I am looking for a library which would generate a mock data based on openapi spec (client side only)So the idea is not to have a separate local server, as it's done in openapi-mock-express-middleware, but rather have data to be generated on fly inside...

109
TypeError: models[model].defineConstraints is not a function

TypeError: models[model].defineConstraints is not a function

I`m trying to undestand whats going on and why defineConstraints is not a functioncan someone help me ?

107