Yo,
Alright been noodling on this one for a while: How copy/cut styled text without bringing along any style baggage (background-color, color, etc)?
Couple of routes of attacks that have been foiled:
- Style the text differently using ::select? Doesn’t work, ::style isn’t copied
- Style the selected text using jQuery’s select binding This only works for inputs, not p, divs
- Intercept and remove style by binding an event to copy/paste using jQuery? Can’t access the copied object to remove stuff, tried using e.preventDefault(); then returning the event object but that didn’t work either
- Modify the clipboard data once it’s been saved? Also no dice, most browsers wont let you into this without flash and some sort confirmation
Anyway, thoughts? Seems like it would be very useful for sites that have white background colors.
I haven’t got time to code up an example now, but you could do this for cut/copy triggered by keyboard shortcuts. It wouldn’t work for cut/copy via context menu or Edit menu options because it relies on changing the user selection before the cut or copy event fires.
The steps:
window.getSelection().getRangeAt(0).cloneContents(), although you’ll need separate code for IE < 9 and you should check the selection is not collapsed.window.setTimeout()that calls a function that removes the offscreen element and restores the original selection.