搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

Unable to paste into CKEditor WYSIWYG textarea

more options

I've encountered this on several web sites; I'm unable to paste text into textareas that are controlled by CKEditor. If I try a different browser (Safari) on the same web site, paste works without an issue. I see no error messages, but simply when I paste nothing happens. It's happened to me in Firefox on two completely different web sites that are unrelated, and probably using different versions of CKEditor (the buttons have a different look).

I've encountered this on several web sites; I'm unable to paste text into textareas that are controlled by CKEditor. If I try a different browser (Safari) on the same web site, paste works without an issue. I see no error messages, but simply when I paste nothing happens. It's happened to me in Firefox on two completely different web sites that are unrelated, and probably using different versions of CKEditor (the buttons have a different look).

所有回覆 (7)

more options

Pasting works for me in the CKEditor demo on their site. Does it still happen in Troubleshoot Mode?

more options

Yes, just confirmed that pasting text works in troubleshoot mode, but i cannot paste into any ckeditor when i turn it off. That means it must be an extension, right? so I just have to start disabling the extensions and restarting to figure out which one is interfering?

Thanks so much for this help!

more options

Turns out it was Greasemonkey. I have a very vague recollection of doing something with it a very long time ago, but I'm not sure. Maybe it might have been something to do with finding a way to disable web sites' ability to disable paste into password/email fields? You know how some web sites used to want to make you manually type something into a field instead of copy/pasting into the field? That would sort of make sense since it's related, but the point of the script was to stop web sites from being able to disable paste, which is a bit confusing.

more options

Ah.. I just realized I needed to enable the greasemonkey extension before I could edit the extensions. I totally forgot about this script, but here it is:

// ==UserScript== // @name Force Allow Paste // @version 1 // @grant none // ==/UserScript==

var allowPaste = function(e){

 e.stopImmediatePropagation();
 return true;

}; document.addEventListener('paste', allowPaste, true);

How is it possible that this script that overrides any JS functionality that would attempt to disable paste could prevent paste in certain JS environments?

more options

safetypin said

Ah.. I just realized I needed to enable the greasemonkey extension before I could edit the extensions. I totally forgot about this script, but here it is:
// ==UserScript==
// @name     Force Allow Paste
// @version  1
// @grant    none
// ==/UserScript==

var allowPaste = function(e){
  e.stopImmediatePropagation();
  return true;
};
document.addEventListener('paste', allowPaste, true);
How is it possible that this script that overrides any JS functionality that would attempt to disable paste could prevent paste in certain JS environments?

In most cases, Greasemonkey scripts are added to the page and run after the page's own scripts, so they override any built-in scripts. Otherwise, they'd be kind of useless...

By the way, *monkey extensions usually have a configuration panel where you can exclude sites from the script, if you want to keep using it for most sites but disable it on sites where you notice a problem. This makes using a script more flexible than using the similar built-in setting that hides clipboard actions from sites (since that has no way to make exceptions).

more options

Thanks for the tip about excluding sites. That will work for me, as it's really only been a few sites that I've encountered that i'm unable to paste on, so it's a good workaround.

Well, yes. I understand the scripts need to run after the scripts on the site. What I mean is, from a programming perspective, I don't understand how a script that is designed to stop sites from disallowing paste functionality could result in paste being disabling.

How could this line of code stop paste from working?

document.addEventListener('paste', allowPaste, true);

more options

safetypin said

How could this line of code stop paste from working? document.addEventListener('paste', allowPaste, true);

What that line does is instruct Firefox to run the allowPaste() function when it is sending a paste event to the page.

The allowPaste() function stops Firefox from sending the paste event to any other scripts in the page that might be listening for a paste event. It hides your paste action from other scripts.

The effect of that depends on how the form is set up.

If the site has basic HTML forms, or if it just allows free access to a rectangle in the page, then it doesn't matter whether Firefox hides the paste action from the scripts running in the page, because Firefox itself is inserting the text.

However, if the site is designed so that your paste is directed toward a non-editable element (like the blank body area of this page), then the paste goes nowhere unless/until the site intercepts the paste and inserts it into the proper location. Rich text editors often micromanage the editing process that way to create a full "word processing" experience.