1. Create HTML file
Open terminal and create blank HTML file.
$ sudo vi text.html
Add the following HTML file.
<!-- The text field --> <input type="text" value="Hello World" id="myInput"> <!-- The button used to copy the text --> <button onclick="copy_to_clipboard()">Copy to Clipboard</button>
The above HTML file adds a textbox and button. We have also added an event for clicking the button.
In the above script we have added an event handler copy_to_clipboard() for click event fired when you click the button on HTML page. In that function, we first select our textbox. Then we use execCommand() to copy the text in textbox to clipboard. Finally, we display an alert box confirming that our text is copied. You can try pasting the copied in another document such as .txt file by simply typing Ctrl+P (Windows).
Please note, you can use the above function to copy text from other HTML elements also such as paragraphs or div, since we are using the id attribute of textbox to identify the element.
That’s it. As you can see, ever since browsers have started supporting copy to clipboard functionality, it has become very easy to add this feature on any web page, static or dynamic. You can easily modify and add it to your website/web application.
How to Check Command Executed by User in Linux
How to View User Login History in Linux
How to Send Email in Python
How to Restrict SSH Access to Specific IP Address
How to Find Users Currently Logged in Linux