复制到剪贴板 flask

huangapple go评论71阅读模式
英文:

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 %}

huangapple
  • 本文由 发表于 2023年4月10日 18:40:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/75976373.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定