[HTML] Make A Button To Copy Text - Clay-Technology World
Có thể bạn quan tâm
I have always wanted to make a button to copy the text of a html block, that can help a project I am developing very well. Therefore, I studied it today and recorded it.
The method of implementation is also quite simple. You only need to set the ID of the block to be copied.
Demo <p id="copy">This is the copy string!</p> <button type="button" onclick="copyEvent('copy')">Copy</button> <script> function copyEvent(id) { var str = document.getElementById(id); window.getSelection().selectAllChildren(str); document.execCommand("Copy") } </script>This is the copy string!
Copy COPYThe top block, the block with id="copy", is the text I expect to copy “This is the copy string!”. Below is a simple button, which is triggered by the JavaScript script below.
In JS, I defined a copyEvent() function, which is mainly to copy the string corresponding to the block with a specific ID.
The displayed screen is as follows:

After clicking, find a notepad to paste:

Share this:
- X
相關
Từ khóa » Html Code To Copy Text
-
How To Copy To Clipboard - W3Schools
-
How To Copy Text From An HTML Element (div, P, Span) To The Clipboard
-
Copy Text To Clipboard Button Html Code Example
-
How To Copy TEXT To Clipboard On Button-Click - CodePen
-
HTML Codes
-
Copy Text To Clipboard In Html Using Javascript - DEV Community
-
How To Create Copy To Clipboard Button ? - GeeksforGeeks
-
Add A 'copy Code To Clipboard' Button To Your Blog's Code Blocks
-
How To Copy Code From A Website - ThoughtCo
-
Text/html Copy To Clipboard Without Any Style - Stack Overflow
-
How To Copy Text To The Clipboard With HTML And JavaScript
-
Clipboard.js — Copy To Clipboard Without Flash
-
Interact With The Clipboard - Mozilla - MDN Web Docs
-
Copying HTML To Create A New Page (or Archive It)