html - TinyMCE 从 iframe 元素中去除类属性

标签 html css tinymce

我想使用类属性定位特定的 iframe,以便使用 CSS 设置宽度。

iframe 是谷歌地图嵌入,如下所示:

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="https://maps.google.co.uk/?ie=UTF8&amp;t=m&amp;ll=52.8382,-2.327815&amp;spn=4.646012,9.338379&amp;z=6&amp;output=embed"></iframe>

它们被复制并粘贴到tinyMCE的HTML源代码编辑器中。我需要将类属性应用到 iframe,但在源编辑器上单击更新时它会被删除。

我尝试在配置中使用 valid_elements 和extended_valid_elements,但都不适用于 iframe[class]。

我正在运行版本 3.4.3。我下载了3.5.7,似乎也有同样的问题。尽管 valid_elements 的文档声明支持类属性 (http://www.tinymce.com/tryit/full.php),但该行为也在 tinyMCE 网站 (http://www.tinymce.com/tryit/full.php) 的演示中展示。 com/wiki.php/Configuration:valid_elements)。

这是完整的配置:

tinyMCE.init({
    // General options
    mode : "specific_textareas",
    editor_selector : "formInputWysiwyg",
    theme : "advanced",
    plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,wordcount,advlist",

    // Theme options
    theme_advanced_buttons1 : "bold,italic,strikethrough,formatselect,styleselect,undo,redo,|,code,|,fullscreen,",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,search,replace,|,bullist,numlist,|,blockquote,nonbreaking,|,charmap,media,|,link,unlink,anchor,image",
    theme_advanced_buttons3 : "",
    theme_advanced_buttons4 : "",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true,
    width : "500",
    height : "600",
    apply_source_formatting : true,
    remove_linebreaks: true,
    theme_advanced_blockformats : "p,blockquote,h1,h2,h3,h4,h5,h6",
    forced_root_block : false,
    plugin_preview_width : "1050",
    plugin_preview_height : "800",
    convert_urls : false,
    extended_valid_elements : "figure,figcaption",

    // Skin options
    skin : "o2k7",
    skin_variant : "silver",

    // Example content CSS (should be your site CSS)
    content_css : "/admin/includes/css/tinymce.css",

    // Drop lists for link/image/media/template dialogs
    template_external_list_url : "lists/template_list.js",
    external_link_list_url : "lists/link_list.js",
    external_image_list_url : "lists/image_list.js",
    media_external_list_url : "lists/media_list.js",

    // Style formats
    style_formats : [
        {title : 'Google Maps', selector : 'iframe', classes : 'google-maps-embed'},
        {title : 'Intro', selector : 'p', classes : 'intro'},
        {title : 'News Image', selector : 'img', classes : 'news-image'}
    ],
});

最佳答案

在\tinymce\jscripts\tiny_mce\plugins\media\editor_plugin_src.js 中,我通过从第 12 行的 rootAttributes 中删除“class”解决了这个问题,然后使用 jscompress.com 进行缩小并替换了editor_plugin.js 文件(在同一文件夹中)。

更改:

 var rootAttributes = tinymce.explode('id,name,width,height,style,align,class,hspace,vspace,bgcolor,type')

致:

 var rootAttributes = tinymce.explode('id,name,width,height,style,align,hspace,vspace,bgcolor,type')

这在 3.5.8 中仍然是一个问题,并已将其作为 bug 提交。

关于html - TinyMCE 从 iframe 元素中去除类属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13161323/

相关文章:

php - header 在我的 PHP 代码中没有响应

html - 切换按钮的正确选择器

javascript - 将 div 放在新行中

html - 我想从模态主体和页脚中删除水平线?

html - 使元素脱离正常流程的 CSS 属性是什么?

javascript - Chartist.js 在 vue.js 中显示工具提示

Javascript 和 TinyMCE(无法使用 TinyMCE 更改 .value 或 textarea)

ruby-on-rails-3 - 无法在 TinyMCE 中更改 DocumentBaseUrl

javascript - 索引.js :1 Uncaught SyntaxError: Unexpected token <

javascript - 在tinymce中改变行的高度