英文:
copy to clipboard flask
问题
link is being sent to the page via render_template, and is generated on page load. Any ideas welcome!
英文:
I'm trying to copy a share link to the clipboard in a flask app I have.
My html page is as follows:
{% 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 %}
link is being sent to the page via render_template, and is generated on page load.
Any ideas welcome!
答案1
得分: 1
你有一个开头的button
和一个结束的tag
,你应该把你的<script>
标签放在<head>
内。
{% extends 'index.html' %}
{% block content %}
<h1 class="display-3">分享就是关怀!</h1>
<p>目前,支持这个项目最好的方式是分享。</p>
<div>
<button class="btn btn-primary" onClick="copyToClipboard('{{link}}')">复制链接</button>
</div>
{% endblock %}
{% block scripts %}
<script>
function copyToClipboard(link) {
navigator.clipboard.writeText(link)
}
</script>
{% endblock %}
英文:
You have an opening button
and a closing a tag
and you should put your <script>
tag inside <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 %}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论