Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 120 posts 448 karma points
    Oct 21, 2014 @ 10:40
    Tom
    0

    RTE and javascript

    Hi,

    I'm trying to allow editors to insert js into a RTE. I've followed this: http://our.umbraco.org/wiki/how-tos/customizing-the-wysiwyg-rich-text-editor-(tinymce)/allow-any-markup-in-the-tinymce-editor

    but when inserting a script-tag, for example:

    <script>
    $(function(){alert("hello");});
    </script>
    

    I come out like this when rendering with @Html.Raw(CurrentPage.bodyText)

    <script>
    // <![CDATA[
    $(function(){
    alert("hello");
    });
    // ]]
    

    Missing a closing tag and all. What to do?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Oct 21, 2014 @ 11:01
    Dennis Aaen
    0

    Hi Tom,

    The way we normally do it on my work is like whenever we need to put a piece of javascript on one of the sites, we tend to use the textbox multiple to place the javascript code in instead of place the javascript code inside the RTE (unless I'm having the script inside one the specific macro of course ).

    The textbox multiple will not strip any of the script that you inserted into it.

    So this could maybe be the solution for you too to solve your issue with Javascript inside the RTE.

    Hope this helps,

    /Dennis

  • Tom 120 posts 448 karma points
    Oct 21, 2014 @ 11:04
    Tom
    0

    yeah, thanks. Guess thats the only viable way.

  • Tom 120 posts 448 karma points
    Oct 21, 2014 @ 13:22
    Tom
    0

    Anyone who successfully have gotten scripts to work in the RTE? My editors needs to be able to insert scripts all kinds of places...

  • Danny Blatant 91 posts 358 karma points
    Oct 21, 2014 @ 18:10
    Danny Blatant
    0

    Just a quick one, the artcile you linked to, mentions addingthe CDATA markup to validElements, but did you add the script tags to

    This might be why it's cleaning the closing tag??

    Also, are the scripts pre-defined, so the user can choose? eg. Carousel script, Model script, Fancy Script, ect??

    If this is the case why not use the ClientDependancyFramework and present a checkbox list of scripts undeer the RTE field (labeled something like "Scripts to include with RTE") so the editor can pick the scripts?

    You don't need the Javascript executing within the actual editor do you? just on display right?

    Kind Regards,

    Danny "Blatant"

Please Sign in or register to post replies

Write your reply to:

Draft