I want to copy an image to clipboard when a button is clicked but when I paste it, it always has style="..."
which I want to remove.
I used the function from another Stack Overflow question.
function copy(selector) {
var $temp = $("<div>");
$("body").append($temp);
$temp.attr("contenteditable", true)
.html($(selector).html())
.select()
.on("focus", function() { document.execCommand('selectAll', false, null); })
.focus();
document.execCommand("copy");
$temp.remove();
}
Here is the HTML:
<p id="demo"><img src="/picture/img.jpg" alt="img"></p>
<button onclick="copy('#demo')">Copy Keeping Format</button>
When I click the button and paste it in a web text editor such as TinyMCE it displays the image, but when I open the source code it has style="..."
which I obviously don't need:
<img src="/picture/img.jpg" alt="noname" style="box-sizing: border-box; border: 0px; vertical-align: middle; color: #454545; font-family: 'Helvetica Neue', Roboto, Arial, 'Droid Sans', sans-serif; font-size: 13px; background-color: #f9f9f9;" />
How do I make it paste just the following?
<img src="/picture/img.jpg" alt="noname"/>
How i check the data will be copy ?
console.log() // what var to print to check the data that will be copy by execcommand
UPDATE
i try to right click the image and chose copy image and paste it to the text editor and check the source code and get clean img html without style="..."
so its not the text editor add the style="..."
right ?