Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is really in my clipboard? how does it interact with webpage?

When I copy some content in a webpage, what will really happen? What will be saved in my clipboard buffer?

I once thought it's plant text, however, I can paste it's style or images in M$ Word or some web WYSIWYG editors such as TinyMCE. And it isn't html code, otherwise I will see tags in gedit or Notepad.

My main questions are:

  1. where are the document which explains the knowledge about clipboard?
  2. When I make webpages, is it possible to control what users will copy into clipboard with javascript?
like image 687
Lai Yu-Hsuan Avatar asked Jan 03 '12 15:01

Lai Yu-Hsuan


People also ask

Do websites have access to your clipboard?

Yes there is definitely a danger that websites can access your clipboard data. On desktop browsers, it may be true that this can happen only if you have granted permission or dismissed a warning dialog.

What happens when something is copied to clipboard?

The Clipboard is a holding place on your computer where you can temporarily store data (text, pictures, and so on). When you copy something, your selection is held on the Clipboard, where it remains until you copy something else or shut down your computer.

What is a website clipboard?

Web clipboard is ideal for copying and pasting multiple sections of a document, because you can queue sections and then paste them in to a new document. Use the web clipboard to copy everything you need from a doc, rather than having to switch between 2 docs, copying and pasting sections one after another.


3 Answers

On Windows (and I'm guessing some or most other OS's), the clipboard can hold data in multiple formats. In Word, for instance, when you copy text to the clipboard, both plain text and formatted text are copied there. You can use various clipboard functions to see what formats the data is available in. A plain text editor like Notepad will use the plain text if available; an editor that understands formatted text will use that instead. So the browser copies both plain and HTML text to the clipboard, and then the program pulling from the clipboard when you paste will choose the best format to use.

where are the document which explains the knowledge about clipboard?

For Windows (just to get an idea conceptually of how this stuff works on a mature OS), you can get a fair bit of information about this by kicking around the docs for the .Net Clipboard class and its associated interfaces, like IDataObject.

For browsers and JavaScript, there is no current standard. There is a proposed one, but nothing widely supported yet.

When I make webpages, is it possible to control what users will copy into clipboard with javascript?

Not that I'm aware of (except the above proposed API), not using just JavaScript; the browser does what it thinks best (usually copying both plain and formatted text).

like image 96
T.J. Crowder Avatar answered Nov 02 '22 22:11

T.J. Crowder


Background

In Windows, there is a plain text clipboard and a MIME-aware clipboard; when you copy, you'll get the plain text version and the rich HTML. Text editors like Notepad will just take from the plain buffer, whereas a program like Word will look in the MIME section and try to do clever stuff with the HTML it finds there.

GUI toolkits in other OSs probably do similar things.

Your questions

1. Where are the documents which explain the Windows clipboard?

I don't know.

2. When I make webpages, is it possible to control what users will copy into clipboard with javascript?

Not really; the GUI and the browser are responsible for what the "clipboard" even means.

like image 38
Lightness Races in Orbit Avatar answered Nov 02 '22 22:11

Lightness Races in Orbit


Currently there isn't a method to interact with a user clipboard using JUST Javascript (there is a working draft out there - see http://www.w3.org/TR/clipboard-apis/).

However you can take control over it using ZeroClipboard for example (uses Flash and a Javascript interface). See http://code.google.com/p/zeroclipboard/

like image 21
nav Avatar answered Nov 02 '22 22:11

nav