Js error with a custom link

5 posts, 0 answers
  1. o.courtois
    o.courtois avatar
    13 posts
    Member since:
    Jul 2007

    Posted 30 Apr 2008 Link to this post

    I have made a custom dialog to create a custom link. This dialog paste the following code in the editor
    <a href="http://www.myurl.com" onclick="xt_med('C', '2', 'XitiClicName', 'N')">TitleLink</a>  

    all works fine, expect if i click on the link in the radeditor ( js error with IE7 , work fine with Firefox).
    Error line 20
    Undefined object

    I'm using Q1 2008 radeditor.
  2. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 08 May 2008 Link to this post

    Hi Olivier,

    The reported error pops up because the editor's content area is an IFRAME which is another document and the javascript xt_med function is placed on the parent page. So the onclick event of the IMG tag cannot locate the xt_med function in the editor's content area and the js engine throws the error when you click on the image.

    In order to achieve your scenario you should use the solution below that imports the external js code in the editor's content area:

    <asp:ScriptManager ID="ScriptManager1" runat="server" />
    <script id="PageJavaScript" language="javascript" type=text/javascript>
    function test1()
    {
        alert("test");
    }
    </script>  
    <script type="text/javascript">
    function OnClientLoad(editor, args)
    {
        var encodeScriptsFilter = editor.get_filtersManager().getFilterByName("EncodeScriptsFilter");
        editor.get_filtersManager().remove(encodeScriptsFilter);

        var oPageScript = document.getElementById("PageJavaScript");
                                        
        var oScript  = "<script defer='false'>\n" + oPageScript.innerHTML + "\n</" + "script>";  
        editor.setFocus();
        editor.set_html(editor.get_html(true) + oScript);
    }
    </script>
    <telerik:RadEditor ID="RadEditor1" OnClientLoad="OnClientLoad" runat="server">
        <Content>
            <img onclick="test1();" src="http://www.telerik.com/r.a.d.controls/Editor/Img/productBox.gif">   
        </Content>
    </telerik:RadEditor>


    All the best,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 08 May 2008 Link to this post

    Just a quick follow-up!

    I forgot to wrote that you should also disable the RemoveScripts client-side filter of RadEditor that strips by default all script tags in the editor. To do that use the DisableFilter server method of RadEditor, e.g.

    RadEditor1.DisableFilter(EditorFilters.RemoveScripts);


    Best regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Shaun Peet
    Shaun Peet avatar
    571 posts
    Member since:
    Aug 2004

    Posted 26 Jul 2010 Link to this post

    Hi Rumen,

    Is there a particular reason why the "RemoveScripts" filter can't be enabled/disabled on the client?  I want to disable the user from using scripts in potentially high-impact areas.  Thanks,

    Shaun.
  6. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 27 Jul 2010 Link to this post

    Hi Shaun,

    The name of the client filter is StripScriptsFilter and you could disable it with the following code:

    <script type="text/javascript">
        function OnClientLoad(editor, args) {
            var removeScriptsFilter = editor.get_filtersManager().getFilterByName("StripScriptsFilter");
            editor.get_filtersManager().remove(removeScriptsFilter);
        }
    </script>
    <telerik:RadEditor ID="RadEditor1" OnClientLoad="OnClientLoad" runat="server"></telerik:RadEditor>

    Please, note that this will work for script tags that are pasted in HTML or Design mode. If you load script tags via the Content property they will be stripped. That is why it is better to disable the RemoveScripts filter on the server.

    Sincerely yours,
    Rumen
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017