How to make tinymce paste in plain text by default

后端 未结 11 1030
忘掉有多难
忘掉有多难 2020-12-02 04:24

Googled it thousands of times, No one gives a complete solution of how to make Tinymce paste in plain text by default and strip out any formatting without clicking the \"pas

11条回答
  •  佛祖请我去吃肉
    2020-12-02 05:27

    I did as follows:

    var pastePlainText = function() {
        // No need to pass in an ID, instead fetch the first tinyMCE instance
        var ed = tinyMCE.get(0); 
        ed.pasteAsPlainText = true;  
    
        //adding handlers crossbrowser
        if (tinymce.isOpera || /Firefox\/2/.test(navigator.userAgent)) {
            ed.onKeyDown.add(function (ed, e) {
                if (((tinymce.isMac ? e.metaKey : e.ctrlKey) && e.keyCode == 86) || (e.shiftKey && e.keyCode == 45))
                    ed.pasteAsPlainText = true;
            });
        } else {            
            ed.onPaste.addToTop(function (ed, e) {
                ed.pasteAsPlainText = true;
            });
        }
    };
    

    And then:

    tinyMCE.init({
        // ...
        plugins: "paste",
        oninit: pastePlainText // Note, without "
        // ...
    })
    

提交回复
热议问题