I use the syntax below to download the file described in it, but it was opening in another page instead of downloading it. The syntax is as follow;
function passwd() {
var password = prompt('Enter the pin to download the file: ');
if (password.toLowerCase() == "1472") {
window.open("folder/file")
} else {
alert("incorrect password!! please try again");
}
}
<input type="button" value="download" onClick="passwd()" />