我正在尝试将 html 标签 '<' '>' 替换为 '<' 和“>” 在我的 TinyMCE 文本中,在进行页面回发之前。
使用 TinyMCE v.3.xi 可以这样做:
function saveCallback(element_id, html, body) {
html = html.replace(/</gi, "<");
html = html.replace(/>/gi, ">");
return html;
}
function loadCallback(type, value) {
if (type == "insert_to_editor") {
value = value.replace(/</gi, "<");
value = value.replace(/>/gi, ">");
}
return value;
}
tinyMCE.init({
...
save_callback: "saveCallback",
cleanup_callback: "loadCallback"
});
Run Code Online (Sandbox Code Playgroud)
使用新的 TinyMCE v.4.x,我尝试这样做:
$(function () {
tinymce.init({
language: "it",
width: 500,
height: 400,
formats: false,
menubar: false,
mode: "exact",
elements: "Testo",
setup: function (editor) {
editor.on('SaveContent', function (e) {
html = editor.getContent();
html = html.replace(/</gi, "<");
html = html.replace(/>/gi, ">");
editor.getElement().value = html;
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
并以这种方式:
$(function () {
tinymce.init({
language: "it",
width: 500,
height: 400,
formats: false,
menubar: false,
mode: "exact",
elements: "Testo",
setup: function (editor) {
editor.on('submit', function (e) {
html = editor.getContent();
html = html.replace(/</gi, "<");
html = html.replace(/>/gi, ">");
editor.getElement().value = html;
});
}
});
});
Run Code Online (Sandbox Code Playgroud)
但回发值始终包含 html 标记,并且页面返回消息“检测到潜在危险的 Request.Form 值”
小智 4
在init中尝试以下选项
encoding : 'xml',
setup: function (editor) {editor.on('SaveContent', function (e) {e.content = e.content.replace(/'/g, '&apos');});}
Run Code Online (Sandbox Code Playgroud)
仅供参考:改编自您上面的代码和参考:
对我有用:),希望有帮助。
| 归档时间: |
|
| 查看次数: |
4890 次 |
| 最近记录: |