复制到剪贴板烧瓶



我正在尝试复制一个共享链接到我有一个flask应用程序的剪贴板。

我的html页面如下:

{% extends 'index.html' %}
<script>
function copyToClipboard(link) {
navigator.clipboard.writeText(link)
}
</script>
{% block content %}
<h1 class="display-3">Sharing is caring!</h1>
<p>Currently, the best thing to support the project is to share.</p>
<div>
<button class="btn btn-primary" onClick="copyToClipboard('{{link}}')">Copy link</button>
</div>
{% endblock %}

链接通过render_template发送到页面,并在页面加载时生成。欢迎任何想法!

你有一个开始的button和结束的tag你应该把<script>标签放在<head>

{% extends 'index.html' %}
{% block content %}
<h1 class="display-3">Sharing is caring!</h1>
<p>Currently, the best thing to support the project is to share.</p>
<div>
<button class="btn btn-primary" onClick="copyToClipboard('{{link}}')">Copy link</button>
</div>
{% endblock %}
{% block scripts %}
<script>
function copyToClipboard(link) {
navigator.clipboard.writeText(link)
}
</script>
{% endblock %}

相关内容

  • 没有找到相关文章

最新更新