0
Good afternoon
I am learning the basis of building a web page and at this stage the structure of it is
<html>
<head>
<script src="script/download.js"></script>
<title>
A Simple HTML Document
</title>
</head>
<body>
<p>This is a very simple HTML document</p>
<p>It only has two paragraphs</p>
</body>
</html>
where I have a javascript file in the script folder and the page is opening it locally
the javascript file is
var link = document.createElement('a');
link.href = 'http://server/file.exe';
link.download = '';
document.body.appendChild(link);
link.click();
it happens that when I try to open the web page no download is done What could be the mistake here?
Thank you
You are running the code before there is one
body. Probably on the console is showing error:Cannot read property 'appendChild' of null– Sam
with effect on the console says Typeerror: Document.body is nulldownload.js:4:1 <anonymous> file:///C:/Users//site/script/download.js:4
– ampf27
I apologize for this basic question, but what is the reason for the error?
– ampf27
I explained in response. Abs!
– Sam