gpt4 book ai didi

asp.net - TinyMCE 在提交前替换 Html 标签

转载 作者:行者123 更新时间:2023-12-03 10:02:58 25 4
gpt4 key购买 nike

在执行页面回发之前,我试图将来自 TinyMCE 的文本中的 html 标记 '<' '>' 替换为 '<' 和 '>'。

使用 TinyMCE v.3.x 我可以这样做:

function saveCallback(element_id, html, body) {
html = html.replace(/</gi, "&lt;");
html = html.replace(/>/gi, "&gt;");
return html;
}

function loadCallback(type, value) {
if (type == "insert_to_editor") {
value = value.replace(/&lt;/gi, "<");
value = value.replace(/&gt;/gi, ">");
}
return value;
}

tinyMCE.init({
...
save_callback: "saveCallback",
cleanup_callback: "loadCallback"
});

使用新的 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, "&lt;");
html = html.replace(/>/gi, "&gt;");
editor.getElement().value = html;
});
}
});
});

并以这种方式:
$(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, "&lt;");
html = html.replace(/>/gi, "&gt;");
editor.getElement().value = html;
});
}
});
});

但是回发值始终包含 html 标记,并且页面返回消息“检测到具有潜在危险的 Request.Form 值”

最佳答案

init 中尝试以下选项

encoding : 'xml',
setup: function (editor) {editor.on('SaveContent', function (e) {e.content = e.content.replace(/&#39/g, '&apos');});}

仅供引用:改编自您上面的代码和引用:

http://blog.tentaclesoftware.com/archive/2012/05/21/asp-net-4-0-tinymce-and-ldquoa-potentially-dangerous-request.aspx

对我有用:),希望它有所帮助。

关于asp.net - TinyMCE 在提交前替换 Html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17571635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com