简体   繁体   English

HTML5, CSS, JS 如何在个人网站上创建一个允许下载简历的按钮

[英]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).这意味着页面和文件必须共享相同的域、子域、协议(HTTP 与 HTTPS)和端口(如果指定)。 Exceptions are blob: and data: (which always works), and file: (which never works).例外情况是 blob: 和 data:(始终有效)和 file:(永远无效)。
  • 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/ahttps://itnext.io/how-to-download-files-with-javascript-d5a69b749896

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何创建允许用户后退的按钮? - How do I create a button that allows a user to go backwards? 如何使用 HTML、css 和 javascript 创建此 hover 按钮 - How do I create this hover button Using HTML, css and javascript CSS3 / HTML5 / JS-如何创建带有幻灯片效果的动画纹理背景? - CSS3/HTML5/JS - How can I create an animated texture background with slide effect? 如何在不删除之前的情况下创建另一行 - Canvas - JavasScript - HTML5 - CSS - How do I create another line without the previous deleting - Canvas - JavasScript - HTML5 - CSS CSS3或HTML5 - 如何在HTML5页面中浮动像云一样的背景动画? - CSS3 or HTML5 - how do i do a background animation like clouds floating in HTML5 pages? 如何将 JavaScript 确认转换为 HTML5 按钮操作? - How do I convert JavaScript confirm to HTML5 button actions? 如何在 HTML5 的按钮中设置倒计时功能 - How do I make a countdown feature in a button in HTML5 如何在html5,javascript或php中创建进度栏? - How do I create a progress bar in html5, javascript or php? 如何在网格上为HTML5画布创建随机行? - How Do I Create Random Rows For HTML5 Canvas On a Grid? 使用 vue.js 如何将图像制作为允许我路由另一个页面的按钮 - Using vue.js how do I make an image as a button which allows me to route another page
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM