I need to create a link on button click and also click that link with same click. I am testing the approaches mentioned on
<script type="text/javascript">
function download()
{
alert("Hello");
var link=document.createElement("a");
link.href="https://stackoverflow.com/questions/4772774/how-do-i-create-a-link-using- javascript";
document.getElementById(link).click();
// here it says "cannot click on null", means id is not link, then how can i obtain the id
alert("Hello again");
}
</script>
<button type ="button" value="Download" onClick="download();">Downloads</button>
I need this, because, on click of button, i will be making a get call, and i will receive a URL, and then i need to click the URL (Making Download button, link can vary). Is there any other way of doing this?
I refferd: How do I programmatically click a link with javascript?
and
How do I create a link using javascript?
for achieving this, but no success.