I managed to add text to what's being copied using the code in this answer(the second option). However, when I change the string concatenation and add a call to replace
, I get an error "replace is not a function".
copytext = window.getSelection().replace(/some pattern/, 'replace value'); // Fails
The "selection" object seems to be very complex and I can't even find the text inside it. I could call toString
on it but that's not an option because I'm copying HTML from a contenteditable div and I need to preserve the formatting.
I'm trying to do this because I have relative links in the div's content and they're being converted to absolute links in the copied text for some reason. This only happens when accessing my demo from rawgit. Locally, it works normally.
Any ideas on how I could accomplish this?
UPDATE
Here's a jsfiddle with my current setup: https://jsfiddle.net/8kx8v8pb/