This is a migrated thread and some comments may be shown as answers.

Js error with a custom link

4 Answers 90 Views
Editor
This is a migrated thread and some comments may be shown as answers.
o.courtois
Top achievements
Rank 1
o.courtois asked on 30 Apr 2008, 01:12 PM
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.

4 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 08 May 2008, 08:17 AM
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
0
Rumen
Telerik team
answered on 08 May 2008, 08:37 AM
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
0
Shaun Peet
Top achievements
Rank 2
answered on 26 Jul 2010, 01:57 PM
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.
0
Rumen
Telerik team
answered on 27 Jul 2010, 01:01 PM
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
Tags
Editor
Asked by
o.courtois
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Shaun Peet
Top achievements
Rank 2
Share this question
or