将config.allowedContent设置为true后,CKEditor剥离脚本标签

时间:2019-03-25 03:09:26

标签: ckeditor

我正在使用CKEditor v4.5.5。下面是我的config.js,我不知道如何设置它,以便它允许内容中包含脚本标签。

CKEDITOR.editorConfig = function( config ) {
    config.toolbarGroups = [
        { name: 'clipboard',   groups: [ 'clipboard', 'undo' ] },
        { name: 'editing',     groups: [ 'find', 'selection', 'spellchecker' ] },
        { name: 'links' },
        { name: 'insert' },
        { name: 'forms' },
        { name: 'tools' },
        { name: 'document',    groups: [ 'mode', 'document', 'doctools' ] },
        { name: 'others' },
        '/',
        { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
        { name: 'paragraph',   groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ] },
        { name: 'styles' },
        { name: 'colors' },
        { name: 'about' }
    ];

    config.allowedContent = true;
    config.extraAllowedContent = 'div(*)';
    config.height = "250";
    config.removeButtons = 'Underline,Subscript,Superscript';
    config.format_tags = 'p;h1;h2;h3;pre;div';
    config.removeDialogTabs = 'image:advanced;link:advanced';
};

我尝试将scriptscript* script(*)添加到config.extraAllowedContent

我尝试添加以下内容,然后将类preserve添加到脚本标签

config.protectedSource.push( /<([\S]+)[^>]*class="preserve"[^>]*>.*<\/\1>/g );
config.protectedSource.push( /<[^>]+class="preserve"[^>\/]*\/>/g );

我什至用其他线程推荐的以下代码替换了上面的所有内容。

CKEDITOR.editorConfig = function( config ) {
    config.allowedContent = {
        script: true,
        $1: {
            elements: CKEDITOR.dtd,
            attributes: true,
            styles: true,
            classes: true
        }
    };
};

无论我做什么,我都无法添加脚本标签。这是我要添加的以下脚本,它删除了除iframe以外的所有内容

<script type="text/javascript" src=" https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.14/iframeResizer.min.js"></script>
<iframe src=" https://hello.dubsado.com:443/public/form/view/######" frameborder="0" style="width:1px; min-width:100%;"></iframe>
<script type="text/javascript">setTimeout(function(){iFrameResize({checkOrigin: false, heightCalculationMethod: "taggedElement"});}, 30)</script>

0 个答案:

没有答案