Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>The situation has changed since writing this answer: now that Firefox has added support in version 22, all major browsers now support accessing the clipboard data in a paste event. See <a href="https://stackoverflow.com/a/6804718/96100">Nico Burns's answer</a> for an example.</strong></p> <p>In the past this was not generally possible in a cross-browser way. The ideal would be to be able to get the pasted content via the <code>paste</code> event, <a href="http://codebits.glennjones.net/editing/getclipboarddata.htm" rel="noreferrer">which is possible in recent browsers</a> but not in some older browsers (in particular, Firefox &lt; 22).</p> <p>When you need to support older browsers, what you can do is quite involved and a bit of a hack that will work in Firefox 2+, IE 5.5+ and WebKit browsers such as Safari or Chrome. Recent versions of both TinyMCE and CKEditor use this technique:</p> <ol> <li>Detect a ctrl-v / shift-ins event using a keypress event handler</li> <li>In that handler, save the current user selection, add a textarea element off-screen (say at left -1000px) to the document, turn <code>designMode</code> off and call <code>focus()</code> on the textarea, thus moving the caret and effectively redirecting the paste</li> <li>Set a very brief timer (say 1 millisecond) in the event handler to call another function that stores the textarea value, removes the textarea from the document, turns <code>designMode</code> back on, restores the user selection and pastes the text in.</li> </ol> <p>Note that this will only work for keyboard paste events and not pastes from the context or edit menus. By the time the paste event fires, it's too late to redirect the caret into the textarea (in some browsers, at least).</p> <p>In the unlikely event that you need to support Firefox 2, note that you'll need to place the textarea in the parent document rather than the WYSIWYG editor iframe's document in that browser.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload