+1-888-365-2779
Try Now
More in this section

Forums / Bugs & Issues / Can't use javascript in News Article?

Can't use javascript in News Article?

9 posts, 0 answered
  1. Orion
    Orion avatar
    54 posts
    Registered:
    02 Feb 2009
    11 Jan 2010
    Link to this post
    I am trying to embed video into a news article using Javascript.  I added "AllowScripts="true"" to the EditorTemplate for News, and then put the code into the body of an article in HTML view.  It works initially, but as soon as I go back to make any edits to the article, and then save again, it removes the Javascript from the article, killing the video. 

    Can anybody help me with this issue please?

    Thanks,
    Orion
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    11 Jan 2010
    Link to this post
    Hi Orion,

    AllowScripts is used in old versions of Telerik.Web.UI. The newer versions use ContentFilters property. Make sure that RemoveScripts filter is not added to ContentFilters property of the RadEditor control declaration.


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Orion
    Orion avatar
    54 posts
    Registered:
    02 Feb 2009
    11 Jan 2010
    Link to this post
    Which file would that be in?  I looked in "EditorTemplate.aspx" for the News module, and I don't see it in there.  This site is running on 3.6, so it's not the newest code, if that helps.
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    12 Jan 2010
    Link to this post
    Hi Orion,

    From version 3.6 we use embedded templates. First you have to map the external template for the desired view. You can gather more information at How to map a view to an external template, in Sitefinity 3.6 or later?
    By default the script tags should be allowed, not stripped.

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  5. Orion
    Orion avatar
    54 posts
    Registered:
    02 Feb 2009
    12 Jan 2010
    Link to this post
    I'm sorry but I'm still very confused.  I'm not really a programmer, and I'm trying to handle this without pulling in my development team.  I don't understand why I would have to map to an external template.  I have edited EditorTemplate.aspx, and it's located at "/Sitefinity/Admin/ControlTemplates/News.  I did the same thing almost a year ago to the EditorTemplate.aspx file for Generic Content and it worked fine.

    The problem occurs while I'm still in the editor, because I can get the code to work fine if I don't switch over to the Design view of the article.  But as soon as I do, or if I save and come back later and try to edit the article (the default view is Design), then it deletes the Javascript.

    I'm sorry but I don't understand.

    Thanks,
    Orion
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    13 Jan 2010
    Link to this post
    Hello Orion,

    The default ContentFilters for the RadEditor control that is used in 3.6 versions are

    FixUlBoldItalic,FixEnclosingP,IECleanAnchors,MozEmStrong,ConvertFontToSpan,ConvertToXhtml,IndentHTMLContent

    There is not filter that should strip the <script> tags as you said. You also said

     "I'm sorry but I'm still very confused.  I'm not really a programmer, and I'm trying to handle this without pulling in my development team.  I don't understand why I would have to map to an external template."


    Since 3.6 we use embedded templates, so it is not possible to set AllowScripts="true"( which actually should be done for ContentFilters property). Here is one of the initial replies that came from you:

    "I am trying to embed video into a news article using Javascript.  I added "AllowScripts="true"" to the EditorTemplate for News
    "

    Once again, the built-in  RadEditor control for the embedded templates NewsItemNew and NewsItemEdit does not have a filter  that strips the <sctip> tags. You can try adding a simple scipt like this one shown below and see whether it will be removed.

    <script>
    alert("hello");
    </script>

    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Orion
    Orion avatar
    54 posts
    Registered:
    02 Feb 2009
    13 Jan 2010
    Link to this post
    I have a bit of new information.  I was mistaken about the version.  This is one of our older sites, so it is actually on 3.5.  Does this impact your solutions at all?

    Also, I took the sample Javascript you provided, and put it into the body of the article in HTML view.  I switched back over to Design view, and it didn't show up, so I switched back over to HTML view and the Javascript was gone.  Totally disappeared as if I had never put it in there.

    We do plan on upgrading all of our clients to 4.0 by the end of the year, but is there something I can do in 3.5 to fix this for now?
  8. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    14 Jan 2010
    Link to this post
    Hi Orion,

    In 3.5 the templates that are used for inserting and editing News content items are called ControlPanelInsert and ControlPanelEdit. The templates are located under Sitefinity/Admin/ControlTemplates/News

    In both templates you should have the following RadEditor declaration

    <telerik:RadEditor
                                runat="server"
                                ID="contentEditor"
                                ContentAreaCssFile="~/Sitefinity/Admin/Themes/Default/AjaxControlsSkins/Sitefinity/EditorContentArea.css"
                                ToolsFile="~/Sitefinity/Admin/ControlTemplates/EditorToolsFile.xml"                           
                                Skin="WebBlue"
                                DialogsCssFile ="~/Sitefinity/Admin/Themes/Default/AjaxControlsSkins/Sitefinity/EditorDialogs.css"
                                NewLineBr="False"
                                AllowScripts="true"
                                Width="95%">
                                <ImageManager ViewPaths="~/Images" UploadPaths="~/Images" DeletePaths="~/Images" />
                                <MediaManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
                                <FlashManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
                                <DocumentManager ViewPaths="~/Files" UploadPaths="~/Files" DeletePaths="~/Files" />
                                <CssFiles>
                                    <telerik:EditorCssFile Value="~/Sitefinity/Admin/Themes/Default/AjaxControlsSkins/Sitefinity/EditorCssFile.css" />
                                </CssFiles>
                            </telerik:RadEditor>

    AllowScripts should be set to true. Otherwise the script tags (<script>alert("test")</script>) are stripped.


    Greetings,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. Orion
    Orion avatar
    54 posts
    Registered:
    02 Feb 2009
    14 Jan 2010
    Link to this post
    Thank you!  That's exactly what I was missing.
Register for webinar
9 posts, 0 answered