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

Run jscript from editor

6 Answers 73 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Alex Dybenko
Top achievements
Rank 2
Alex Dybenko asked on 09 Apr 2009, 01:26 PM
Hi,
I have an editor in RAD window, and i want to insert a hyperlink into it content to open another window, with video. So i made a function OpenVideo() on a page where editor resides, and inserted following hyperlink into editor content:
this is test <a href="#" onclick="return OpenVideo('Video1');">video link</a>,
But when i click it - i get error object not found. Is it possible to make such hyperlink in editor content so i can run jscipt function on editor's page?
Thanks!

Alex

6 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 13 Apr 2009, 08:30 AM

Hi Alex,

The reported error pops up because the editor's content area is an IFRAME which is another document and the javascript OpenVideo function is placed on the parent page. So the onclick event of the A tag cannot locate the OpenVideo 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>

Regards,

Rumen
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Alex Dybenko
Top achievements
Rank 2
answered on 14 Apr 2009, 01:37 PM
Hi Rumen,
I cannot make your sample working, pasted in on  new web form, but still get Object expected error. Can you check at your side?
Furthermore - in my application editor is place in rad window, and in my function i need to get access to GetRadWindow(), to open apropriate window then, will it work in your approach?

Thanks
Alex
0
Rumen
Telerik team
answered on 17 Apr 2009, 11:25 AM
Hi Alex,

By default the editor remove the script tags in the content area to prevent malicious scripts. In this scenario you should disable this client-side filter by setting the following server method in the codebehind:

RadEditor1.DisableFilter(Telerik.Web.UI.EditorFilters.RemoveScripts);

Please, note however that the content area of RadEditor is another document and when you display the produced by RadEditor content outside it then most likely the javascript code will not work. We do not support your scenario because the editor is intended to be used as HTML / XHTML editor.

Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Alex Dybenko
Top achievements
Rank 2
answered on 21 Apr 2009, 06:18 AM
Hi Rumen,
ok, I have added one more "view", where i show editor content on a page directly, and this solves the problem scripts
thanks!
Alex

0
Henry
Top achievements
Rank 1
answered on 21 Jun 2009, 11:31 AM
Hi Alex,
  I have the same problem, did you solve it without implemeting Rumen's solution?
  You mentioned you solved the javascript problem by creating a new "view". Hope you can kindly explain how you solved this issue, since the editor's content area is on an iframe.

  I would like to have a solution that will still restrict users from entering malicious javascript code from the HTML mode.

Thanks,
Henry Wu
0
Alex Dybenko
Top achievements
Rank 2
answered on 22 Jun 2009, 02:50 PM
Hi Henry,
i have added asp liter control on the same page, so for edit mode i show rad editor and and view mode - i hide editor and fill literal with html cod from editor. now in view mode i can all jscript functions of the page

Alex
Tags
Editor
Asked by
Alex Dybenko
Top achievements
Rank 2
Answers by
Rumen
Telerik team
Alex Dybenko
Top achievements
Rank 2
Henry
Top achievements
Rank 1
Share this question
or