What's new

Welcome to the forum 👋, Visitor

To access the forum content and all our services, you must register or log in to the forum. Becoming a member of the forum is completely free.

How to create copy to clipboard buttons?

stigwest

New member
Joined
Jun 3, 2023
Messages
1
Reaction score
0
HTML Coins
0
Hi! I'm trying to make an easy list of standard answers to use at work, in my service desk function. A copy function such as this would be excellent, but I cannot seem to get it to work with more than one sentence to be copied. When I add a new tag with the same script, with at different standard text, clicking the button for the first text only copies the second text. My code is as follows, any clues to help me? I'd like to make an extensive list, so any tips on how to make this in the most effective way would be very welcome :)

<!DOCTYPE html>
<html>

<head>
<style>
body {
margin: 100px;
}


button {
width: 70px;
height: 40px;
margin-top: -50px;
margin-left: -40px;
background-color: green;
color: white;
border-radius: 10px;
box-shadow: grey;
position: absolute;
}

#Standard1 {
margin-top: 0px;
margin-left: 50px;
}
#Standard2 {
margin-top: 40px;
margin-left: 50px;
}
h1 {
margin-left: -40px;
margin-top: -100px;
font-size: large;
</style>
</head>

<body>
<div id="Standard1">
This is my first standard text
</div>
<br />

<button onclick="copyText()">Copy</button>
<br />

<h1>THESE ARE MY STANDARD TEXTS:</h1><br />

<script>
function copyText() {

/* Copy text into clipboard */
navigator.clipboard.writeText
("This is my first standard text");
}
</script>

</body>
<body>
<div id="Standard2">
This is my second standard text
</div>
<br />

<button onclick="copyText()">Copy</button>
<br />

<script>
function copyText() {

/* Copy text into clipboard */
navigator.clipboard.writeText
("This is my second standard text");
}
</script>
</body>
</html>
 

Theme customization system

You can customize some areas of the forum theme from this menu.

  • Wide/Narrow view

    You can control a structure that you can use to use your theme wide or narrow.

    Grid view forum list

    You can control the layout of the forum list in a grid or ordinary listing style structure.

    Picture grid mode

    You can control the structure where you can open/close images in the grid forum list.

    Close sidebar

    You can get rid of the crowded view in the forum by closing the sidebar.

    Fixed sidebar

    You can make it more useful and easier to access by pinning the sidebar.

    Close radius

    You can use the radius at the corners of the blocks according to your taste by closing/opening it.

  • Choose the color combination that reflects your taste
    Background images
    Color gradient backgrounds
Back