Reputation: 53
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"
Upvotes: 5
Views: 5024
Reputation: 388
With tinyMCE 4 try this clean solution, using the PostProcess event:
tinymce.init({
language: "it",
width: 500,
height: 400,
formats: false,
menubar: false,
mode: "exact",
elements: "Testo",
init_instance_callback: function (editor) {
editor.on('PostProcess', function (e) {
e.content = e.content.replace(/</g, '<');
e.content = e.content.replace(/>/g, '>');
});
},
});
Upvotes: 0
Reputation: 53
I've solved in this way:
tinymce.init({
selector: "#MySelector",
width: ...,
height: ...,
encoding: 'xml',
setup: function (editor) { editor.on('SaveContent', function (e) { e.content = e.content.replace(/'/g, '&apos').replace(/&/g, '&'); }); }
});
Upvotes: 0
Reputation: 56
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:
works for me :) , hope it helps.
Upvotes: 4