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

[Solved] Adding javascript functions to a rad editor

3 Answers 252 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Mike Beaton
Top achievements
Rank 1
Mike Beaton asked on 10 Sep 2009, 04:01 PM
Hi

I seem to be having trouble adding onmouseover events to html tags in my rad editor. Exvery time I add say 

<A href="#" onmouseover="GetDescription(13)">GLOS1</A> 

into the editor and switch to design view the link appears fine but as soon as the mouse runs over the link I get "jscript runtime error: Object expected. I have no idea why this keeps happening as if I add the anchor anywhere else on the page it works fine.

Does anyone have a reason why this could be.

Regards Mike

3 Answers, 1 is accepted

Sort by
0
Ken Jones
Top achievements
Rank 1
answered on 14 Sep 2009, 11:18 AM
Following on from my Colleague's post, I think the issue is that the javascript function that is being called is on the aspx page and not in the content of the radeditor.

This is html that is shown when then error occurs:

<head><style></style></head><body><A onmouseover=GetDescription(13); onmouseout=nd(); href="#">GLOS1</A></body>

Is there a way of getting the javascript into this html?

Ta,

Ken
0
Rumen
Telerik team
answered on 15 Sep 2009, 12:09 PM
Hi guys,

The reported error pops up because the editor's content area is an IFRAME which is another document and the javascript function executed in the inline event attributes is placed on the parent page. So the onmousexxxxx events of the A tag cannot locate the GetDescription function in the editor's content area and the js engine throws the error when you click on the link tag.

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

<script id="PageJavaScript" language="javascript" type=text/javascript> 
function test1() 
    alert("test"); 
</script>   
<script type="text/javascript"
function OnClientLoad(editor, args) 
 
    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" ContentFilters="ConvertFontToSpan,ConvertToXhtml" OnClientLoad="OnClientLoad" runat="server"
    <Content> 
        <img onclick="test1();" onmouseover="test1();" src="http://demos.telerik.com/aspnet-ajax/Common/ProductInfo/Controls_logo.gif">    
    </Content> 
</telerik:RadEditor> 


Best wishes,
Rumen
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.
0
Ken Jones
Top achievements
Rank 1
answered on 22 Sep 2009, 02:27 PM
Hello,

Thanks for your response. I am managed to use a work around that amends the content on edit and update to include and exclude the client side javascript calls. Hopefully this will suffice.

Ta,

Ken
Tags
Editor
Asked by
Mike Beaton
Top achievements
Rank 1
Answers by
Ken Jones
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or