So i am using this script to copy text to the clipboard that needs to be compatible with firefox and chrome at a minimum.
https://github.com/lgarron/clipboard.js
Basically i have some html stored in a php variable and im trying to copy that to the clipboard.The other way i could do it is to copy the contents of a div to the clipboard but basically same result
<script src="js/clipboard.js"></script>
<script>
document.getElementById('markup-copy').addEventListener('click', function() {
var val = '<?php echo $myText ?>';
clipboard.copy({
'text/plain': 'Paste this into a HTML editor.',
'text/html': val;
}).then(
function(){console.log('success'); },
function(err){console.log('failure', err);
});
});
</script>";
Ive also tried doing the same but echoing the string directly i.e
'text/html': '<?php echo $myText ?>';
The script does print out the actual string of html however when i copy it to the clipboard all i see is:
<?php echo $myText ?>
So even though the page translates the above to the string, this script doesnt seem to. Any ideas?
The $myText variable is a string with and some basic HTML, no php.
I want to avoid using a flash based solution however if this simply wont work then ill settle to do it in flash.