Jason Francis
Jason Francis

Reputation: 1104

How can I paste the plain text version of the clipboard's contents into a jQuery lwRTE?

We are using the jQuery lwRTE plugin (http://plugins.jquery.com/project/lwRTE) to collect user input, and we have been quite pleased with its flexibility. We are only interested in allowing basic formatting, and the ability to customize the toolbar has been nice.

One problem we have run into, though, is dealing with the additional (garbage) html formatting that accompanies the text when it is copied from Word (or other applications that offer a html version to the clipboard). We do a pretty good job of cleaning it up on the server, but we would prefer to not have to deal with it at all. It would be nice if we could just get plain text from the clipboard.

The extent of extra formatting we get depends on the browser, but we are seeing at least some on all of them. Is there an execCommand() that I need to enable?

Thanks. Any help would be appreciated.

Upvotes: 1

Views: 910

Answers (2)

belugabob
belugabob

Reputation: 4460

Whenever I come across this kind of situation, I usually paste the text into Notepad first (as it will paste just the plain text portions of the text) - then re-cut the text from there, to the target location. If I remember correctly, this is possible because a 'clip' can have its data stored in several formats, and an application can say something like 'paste as text', 'paste as html' etc. I suppose that the trick would be to get the jquery plugin to do the paste in the right format.

I can't check right now - because of the security policies in place in my office - but try running C:WINDOWS\system32\clipbrd.exe to see what's actually in the clipboard.

I will update this post when I have chance to locate more info.

Quick edit: Check this link for more info - http://msdn.microsoft.com/en-us/library/ms649013(VS.85).aspx

Upvotes: 2

Steven
Steven

Reputation: 19435

This is a pretty common "problem" with many WYSIWYG editors. In worst case, the Word formatting will mess up your page layout as well.

Take a look atthis javascripot: http://www.1stclassmedia.co.uk/developers/clean-ms-word-formatting.php

Call it when you paste the text.

Upvotes: 2

Related Questions