Some time ago I could copy text from an input text or a div in the clipboard, also saving its HTML format. That is, I could copy the text with the HTML tags I had such as p
, strong
, em
, h1
... etc.
For this I used the library Zeroclipboard and everything worked great.
I used the code as explained by Zeroclipboard in Github , although introducing the content in an input text:
HTML
<html>
<body>
<button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me.">Copy to Clipboard</button>
<script src="ZeroClipboard.js"></script>
<script src="main.js"></script>
</body>
</html>
main.js
// main.js
var client = new ZeroClipboard( document.getElementById("copy-button") );
client.on( "ready", function( readyEvent ) {
// alert( "ZeroClipboard SWF is ready!" );
client.on( "aftercopy", function( event ) {
// 'this' === 'client'
// 'event.target' === the element that was clicked
event.target.style.display = "none";
alert("Copied text to clipboard: " + event.data["text/plain"] );
} );
} );
The fact is that now I can not make it work in any way. I have uploaded in the HTML folder the files ZeroClipboard.swf
, ZeroClipboard.js
, main.js
...
I want to make it work in Safari and my operating system is Mac OSX Sierra . I do not know if the non-functioning of Safari or due to the fact that I upgraded Sierra, because the previous code worked in another version of the Operating System.
Does anyone have this library running in Safari?
Or, could you recommend another alternative library?
Or, is it possible to do this with Javascript / jQuery without going through a library?
EDIT
It would be to have text like this in a div
or a input
:
<div id="content">
<p>Este es un párrafo</p>
<p>Este es otro con letras en <em>cursiva</em>, en <strong>negritas</strong>
<br />Y además como saltos de línea</p>
</div>
And that when I click on the Copiar
button I copy the same content, including their respective HTML tags. Or ... more advanced still, although that could do it (I think) ... that when filling div
or input
with content, I also copy it to the clipboard.
The @Carmen response, below, executes the copy action, but gets the text without the HTML tags. I need the full text to enter it in a database.