Here's one usecase that has been baffling me. When I select some text and paste it in any of Google's applications like docs or notebook, it somehow manages to paste the text with its original formatting and sometimes images itself. Can someone tell me how to do this using javascript/jquery?
Edit: One more scenario that I am looking at is say designing a server-based copy/paste mechanism.
The format painter lets you copy all of the formatting from one object and apply it to another one – think of it as copying and pasting for formatting. Select the text or graphic that has the formatting that you want to copy.
Select the paragraph where you want to copy the formatting. On the Home tab, in the Clipboard group, click Copy Formatting. Select the paragraph(s) where you want to replace the formatting. On the Home tab, in the Clipboard group, click Paste, or use the keyboard shortcut Ctrl+V.
You can use contenteditable
to do this:
<div contenteditable="true">Stuff pasted in here will retain their original HTML</div>
Here's a simple demo for this: http://jsfiddle.net/AA3Kq/
Regarding your second scenario, you'll want to look at JavaScript's selection API. I'm not an expert on this, but here's some places where you can get started on:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With