'Is there a way to allow users to copy text from a website, and the text be unformatted?

Pretty much just the question. I have a client that is requesting a negative design with nearly white text all over the webpage, but testers are saying that it's annoying to copy and paste from the website as everything shows up as white text when copying into Word or the like.

Is there a way to either preemptively remove formatting when a user tries to copy text from the website? Or is there a way to hijack what actually gets put on the clipboard?



Solution 1:[1]

Ctrl + alt + v or ctrl +shift + v should paste what's on your clipboard as unformatted text. Very handy for copying code samples to word docs. This should also work on Mac if you substitute cmd for Ctrl

Solution 2:[2]

What goes in the clipboard by default depends on the browser. Text processors like Microsoft Word usually have options to ignore pasted style, so it shouldn't be an issue if they learn how to use it properly.

If you still want to make life easier for people, you could detect copy events and replace the formated text with raw text. This might help you:

How do I copy to the clipboard in JavaScript?

Get the Highlighted/Selected text

Solution 3:[3]

In Word you've got the option to 'Paste as plain text' (or 'Paste without formatting', not sure of the exact name in English). That way, you can easily paste text from any website without markup.

I don't think it should be the responsibility of the website to implement a 'copy without markup'.

Other trick: paste text with markup in Notepad first. Then select it in Notepad and copy again. The clipboard now contains only plain text.

Of course it's hard to educate the users, but unless there is a very good reason why people would be copying texts from the website, I wouldn't make a custom implementation for it. Those implementations, especially when you override default behaviour (capture Ctrl+C), will probably not work well or at least the same in every browser, and they are just a fix for your website, not everyone else's. Also, such a feature might annoy other users who do know how to handle text with mark-up. So I think it's better to let the users figure out themselves.

As for hijacking the clipboard, if you copy HTML, the browser actually copies the content in multiple formats, like HTML, RTF and plain text. If you had the means, you could simply remove the HTML and RTF version from the clipboard and let the plain text version remain. But I'm pretty sure you don't have that much control over the clipboard from the browser.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Community
Solution 3