html - TinyMCE Stripping Out "controlsList" Attribute on HTML 5 Audio Tag
问题描述
In the TinyMCE editor I want to add a valid element attribute, the HTML5 audio and video attribute "controlList". It's an experimental attribute but supported in Chrome and we have a use for it. For example we want the following code to validate in TinyMCE:
<p>
<audio controls="controls" controlsList="nodownload">
<source src="some.mp3" type="audio/mpeg" />
Your browser does not support the audio element.
</audio>
</p>
Right now 'controlsList="nodownload"' is not recognized and stripped out.
Tiny MCE's documentation shows that adding custom tags and attributes is possible using tinyMCE.init (https://www.tiny.cloud/docs/configure/content-filtering/#valid_elements). However I've looked at the source of 2sxc and I am not quite clear about the best way to do this in 2sxc's implementation of TinyMCE.
One possibility seems to be line 2045 of the file \dist\sxc-edit\sxc-edit.js (2sxc 9.14). There I added the tags & attribute to the existing validateAlso:
validateAlso: '@[class]' // allow classes on all elements,
+ ',i' // allow i elements (allows icon-font tags like <i class="fa fa-...">)
+ ",hr[sxc|guid]" // experimental: allow inline content-blocks
+ ",audio[controlsList]"
+ ",video[controlsList]"
However that didn't have the desired effect on my testing server and I don't love the idea of modifying source since my changes will be overwritten by the next patch I apply.
What is the right way to do this?
解决方案
这是一个允许将自定义属性添加到 HTML 标记的解决方法。请注意,此解决方案适用于我们对 HTML5 音频/视频标签的一次性需求,但可能不适用于所有人。
首先,我们在音频标签中添加了一个“my-player”的 id。
<audio id="my-player" controls="controls">
<source src="some.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
然后我们添加了一个脚本,该脚本使用 DNN 页面设置 > 高级 > SEO > 页面标题标签插入所需的属性:
<script>
$( document ).ready(function() {
$('#my-player').attr("controlsList", "nodownload");
});
</script>
在我们的例子中,这个 javascript 属性插入具有预期的效果。
推荐阅读
- python - Python函数在被调用之前执行
- excel - 使用 Excel 表格,适用于所有行的公式,不适用于第一个表格行
- visual-studio-code - 编辑markdown和预览窗格时VSCode跳动打开
- r - ClusterBootstrap::clusbootglm() 需要很长时间才能运行
- tensorflow - 分配给 Tensorflow2 中的切片
- java - 在Java中查找数组中的互补对
- android - 无法获取 ip 或主机名
- python - 在视图中显示其他相关模型的 Django 最佳实践
- python - 是否有一致的方法可以使用硒从 quora 网页中获取第一个答案?
- ios - 如何使用swift在uitableview中制作隐藏视图