This question is very similar to the following question posted here Copy output of a JavaScript variable to the clipboard , but there are a few things unanswered, which i cant figure out. This approach works, but my test var is actually a string on multiple lines, because it contains a few html tags and once copied, each tag with information must appear separate on a line. However once i copy it, on the clipboard this gets copied all in 1 line. How can i modify this in order to copy it properly on multiple lines?
testingVarTest(testvar);
function testingVarTest(testvar) {
var dummy = document.createElement("input");
document.body.appendChild(dummy);
dummy.setAttribute("id", "dummy_id");
document.getElementById("dummy_id").value=testvar;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}