php 在 TinyMCE 中使用新的 iframe 嵌入代码嵌入 YouTube 视频
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4989039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Embedding YouTube video with new iframe embed code in TinyMCE
提问by woel
I tried the old embed code for adding YouTube videos into TinyMCE and it works fine. Some of the users may not realise they have to click on the old embed code option in YouTube embed code link to add it in.
我尝试了将 YouTube 视频添加到 TinyMCE 的旧嵌入代码,效果很好。一些用户可能没有意识到他们必须单击 YouTube 嵌入代码链接中的旧嵌入代码选项才能将其添加。
I want to make it easy for users and allow them to just copy the new embed code directly and paste it on TinyMCE and away they go.
我想让用户更容易,并允许他们直接复制新的嵌入代码并将其粘贴到 TinyMCE 上,然后他们就可以走了。
The new embed code looks like the following example:
新的嵌入代码类似于以下示例:
<iframe title="YouTube video player" width="640" height="390"
src="http://www.youtube.com/embed/VvJ037b_kLs"
frameborder="0" allowfullscreen></iframe>
How do I get TinyMCE to accept the new version of the YouTube embed code with iframe?
如何让 TinyMCE 接受带有 iframe 的新版 YouTube 嵌入代码?
I'm working on a CakePHP site build.
我正在构建 CakePHP 站点。
回答by jhernandis
I think that the use of "extended_valid_elements" is better than edit the original settings.
我认为使用“extended_valid_elements”比编辑原始设置更好。
See that: TinyMCS - extended_valid_elements
回答by satrun77
By default TinyMCE will filter out iframe tag for security reasons. You can add this tag and its attributes to the allowed list of html elements.
默认情况下,TinyMCE 会出于安全原因过滤掉 iframe 标签。您可以将此标记及其属性添加到允许的 html 元素列表中。
See http://tinymce.moxiecode.com/wiki.php/Configuration:valid_elements
见http://tinymce.moxiecode.com/wiki.php/Configuration:valid_elements
Default rule set:
默认规则集:
tinyMCE.init({
// ... other configurations
valid_elements : "@[id|class|style|title|dir<ltr?rtl|lang|xml::lang|onclick|ondblclick|"
+ "onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|"
+ "onkeydown|onkeyup],a[rel|rev|charset|hreflang|tabindex|accesskey|type|"
+ "name|href|target|title|class|onfocus|onblur],strong/b,em/i,strike,u,"
+ "#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|"
+ "src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,"
+ "-blockquote,-table[border=0|cellspacing|cellpadding|width|frame|rules|"
+ "height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|"
+ "height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,"
+ "#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor"
+ "|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,"
+ "-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],-font[face"
+ "|size|color],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],"
+ "object[classid|width|height|codebase|*],param[name|value|_value],embed[type|width"
+ "|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,"
+ "button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|"
+ "valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],"
+ "input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value],"
+ "kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],"
+ "q[cite],samp,select[disabled|multiple|name|size],small,"
+ "textarea[cols|rows|disabled|name|readonly],tt,var,big"
});
add the following to the end of the list
将以下内容添加到列表末尾
,iframe[src|title|width|height|allowfullscreen|frameborder]
I would not recommend to allow users to embed iframe tag in a public website.
我不建议允许用户在公共网站中嵌入 iframe 标签。