How can I create embed code?

So I’ve come across something which I need to find for a project which would also be very useful in general. How can I create the embed code which has the ability to be copied? I require something similar to the youtube embed code snippet, where you can click on the embed area, it highlights the content for you to copy. I’ve been doing some searching but can’t find much as yet.

The most likely way to do that would be with JavaScript, so your thread has been moved to that forum. :slight_smile:

<textarea name="textarea" cols="40" rows="4" wrap="VIRTUAL" readonly="readonly">Code here</textarea>

I tried this however when you click inside it the text vanishes, any ideas so that it doesn’t vanish and instead you can copy it?

Edit: Might be read only, will test and get back here.

To clarify a bit, basically I need to be able to put a code snippet of html into a website which can then be copied. I guess similar to the ones where you see then on tutorial and example sites.

Is there something else on the page that’s causing it to vanish? The testing that I’ve done with the snippet you posted doesn’t show any any symptoms of things vanishing.

Here’s a good simple example:


<textarea id="embedcode" cols="40" rows="4" wrap="VIRTUAL" readonly="readonly">Code here</textarea>


var embedcode = document.getElementById('embedcode');
embedcode.onclick = function () {
    this.select();
}