Hi,
I'd like to allow my users to insert Javascript in the editor.
It seems to work partialy, I can paste Javascript or insert it by the source view. If I look at the preview, my script execute itself and if I submit my form it is correctly saved to the database.
So everything works fine, until I come back to my page. When I want to reload the page, the script in my page is executed and the editor doesn't load itself correctly.
I 've tried to escape it with the HTMLEncode function but it replaced my '<script>' tag by a '<script>' text string.
I would be really interested if anyone had an idea on how to escape my javascript without breaking it and without breaking the editor.
Fred
I'd like to allow my users to insert Javascript in the editor.
It seems to work partialy, I can paste Javascript or insert it by the source view. If I look at the preview, my script execute itself and if I submit my form it is correctly saved to the database.
So everything works fine, until I come back to my page. When I want to reload the page, the script in my page is executed and the editor doesn't load itself correctly.
I 've tried to escape it with the HTMLEncode function but it replaced my '<script>' tag by a '<script>' text string.
I would be really interested if anyone had an idea on how to escape my javascript without breaking it and without breaking the editor.
Fred
RE: Inserting Javascript in the editor
It's weird tho, as in source view it does the & type of deal, but when in wysiwyg mode, the script works.
So, experimentation is in order!
RE: Inserting Javascript in the editor
RE: Inserting Javascript in the editor
When you go to re-edit the text, before you drop the value you should convert all extra symbols to the ampersand versions (like " to " < to < etc). Drop it as the value of a text box.
Then use the replace textbox method of the editor instead of the normal create method. The editor will automatically grab the contents of the textbox and the special symbols will have been converted over until it's normal form.
This seems to work in both Firefox and IE. It might still be trying to execute the javascript, as I'm getting errors in IE, but when I dismiss them the editor still works as normal and the value is as it should be.
RE: Inserting Javascript in the editor
In order to prevent FCKeditor from seeing my scripts, I simply replaced my '<script>' opening and closing tag by '<scr'+'ipt>' and '</scr'+'ipt>'.
And it works !
RE: Inserting Javascript in the editor
RE: Inserting Javascript in the editor
I didn't need to replace anything before submiting my form because Javascript did it for me. When you write 'string1' + 'string2', Javascript appends the second string to the first one giving 'string1string2'. But this is done in the iframe so my page and the editors load properly.