[英]How do I create a button that allows for downloading CV on personal website in HTML5, CSS, JS
I am trying to create a button for my personal portfolio website that allows users to download my CV from clicking on a button.我正在尝试为我的个人投资组合网站创建一个按钮,允许用户通过单击按钮下载我的简历。 I am not sure went wrong in my HTML5 file.
我不确定我的 HTML5 文件出错了。 Right now, when the button is clicked on, it simply opens up the CV on a new page.
现在,当点击按钮时,它只是在新页面上打开 CV。
<div class="d-block d-sm-flex align-items-center"><a class="btn content-download button-main button-scheme" href="resume/BenZhaoResumeSWE.pdf" download="" role="button">Download CV</a>
Let me know if further context around the code is needed.让我知道是否需要有关代码的更多上下文。 Here is what the frontend looks like the on webpage so far.
到目前为止,这是前端在网页上的样子。 The button itself is there and clicking on opens up a new webpage with the CV instead of downloading it.
该按钮本身就在那里,单击它会打开一个包含 CV 的新网页,而不是下载它。 ]( https://i.stack.imgur.com/cLmS5.jpg )
]( https://i.stack.imgur.com/cLmS5.jpg )
I tried using the above line of code and expected it to download the CV straight from the webpage.我尝试使用上面的代码行,并希望它能直接从网页上下载 CV。 Instead it opens up a new page with the CV.
相反,它会打开一个包含 CV 的新页面。 Is this simply because I have not yet put the webpage on a host domain or is this a coding issue?
这仅仅是因为我还没有将网页放在主机域上,还是编码问题?
You can try this one:你可以试试这个:
<a class="btn content-download button-main button-scheme" href="resume/BenZhaoResumeSWE.pdf" download="proposed_file_name" >Download CV</a>
href
is a path that resolves to an URL on the same origin. href
是同源解析为 URL 的路径。 That means the page and the file must share the same domain, subdomain, protocol (HTTP vs. HTTPS), and port (if specified).proposed_file_name
is the filename to save to. proposed_file_name
是要保存到的文件名。 If it is blank, the browser defaults to the file's name.You can use:您可以使用:
<p>Download <a href="/path/to/mycv.txt" download>my cv</a> please.</p>
You will need to get the path correct so that there is a file called mycv.txt in the relevant directory.您需要获取正确的路径,以便在相关目录中有一个名为mycv.txt的文件。 The key point here is the use of the download attribute in the anchor element.
这里的关键点是锚元素中download属性的使用。
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a and https://itnext.io/how-to-download-files-with-javascript-d5a69b749896请参阅https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a和https://itnext.io/how-to-download-files-with-javascript-d5a69b749896
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.