I'm trying to replace the html tag '<' '>' with '<' and '>' in my text from TinyMCE before do the page postback.
With TinyMCE v.3.x i can do in this way:
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"
});
with the new TinyMCE v.4.x i've try in this way:
$(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;
});
}
});
});
and in this way:
$(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;
});
}
});
});
But the postback values always contain the html tag and the page return the message "A potentially dangerous Request.Form value was detected"
try the following options in the init
encoding : 'xml',
setup: function (editor) {editor.on('SaveContent', function (e) {e.content = e.content.replace(/'/g, '&apos');});}
FYI: adapted from your code above and ref:
http://blog.tentaclesoftware.com/archive/2012/05/21/asp-net-4-0-tinymce-and-ldquoa-potentially-dangerous-request.aspx
works for me :) , hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With