Tag: programming

Copying Text To The Clipboard In Pure Javascript

So sometimes you want to be able to just copy text to the clipboard in a web page. This can be more difficult that you first assume. There are going to be two main steps for this process. First, selecting the text that you want to copy to the user’s clipboard. There is no way around this due to the way that the second step works. The second step is copying the selected text to the user’s clipboard.

Alright so with a little bit of googling we can find that there is the Javascript function.

document.execCommand('copy');

This line of code very quickly copies any selected text to the clipboard but first, we have to select the text to copy it. This is where most of the work comes in. The basic select and copy code will look something like this. Well, that’s it. You can change and edit the little bit to fit your needs but that is really the core of it. Select the text then copy it.

Advertisements

The Meme Machine

OK first thing. So I program for fun. I have for a while, I enjoy it and would recommend it to almost anyone. So a small side project that I made recently is a program that downloads images from the website imgur. I wrote it in Python and haven’t really bothered to compile a .exe version so if you want to give it a try your gonna have to follow the installation directions I left on the GitHub. Here is a link to where you can download it. If you find any issues with it or have a problem getting it working just let me know and I can give you a hand. I’ve tested it for Windows and Linux (I don’t have a Mac though) so it will at least work for those platforms. Have fun with it :P.