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

Insert javascript file inside editor's document

7 Answers 267 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Subodh
Top achievements
Rank 2
Subodh asked on 27 Apr 2009, 07:35 AM

 

I can insert my custom css inside editor's document/head object like

<telerik:radeditor runat="server" ID="RadEditor1" >

<CssFiles>

   <telerik:EditorCssFile Value="mycss.css" />

</CssFiles>

</telerik:radeditor>

 

 

 

Similarly I want to insert my custom javascript inside editor's document. How can I do this?

I have developed some custom tools, like my own image and when user mouseovers the image in editor I want to display some alignment buttons or information icons on it. So I have written the code on mouseover-out etc events in my custom js file.

7 Answers, 1 is accepted

Sort by
0
Subodh
Top achievements
Rank 2
answered on 28 Apr 2009, 01:57 PM
well the solution I found is add following script bellow the editor

        var editor = null;  
        function AddJavascriptFile(sfileUrl, oDocument) {  
            var theDoc = oDocument != null ? oDocument : document;  
            var oScript = theDoc.createElement("script");  
            oScript.setAttribute("src", sfileUrl, 0);  
            oScript.setAttribute("type""text/javascript");  
            var oHead = theDoc.getElementsByTagName("head")[0];   
            oHead.appendChild(oScript);  
        }  
 
        Sys.Application.add_load(function() {  
            var editor = $find("<%=RadEditor1.ClientID%>"); //get a reference to RadEditor's client object  
            var oDocument = editor.get_document(); //  
            AddJavascriptFile("myownjavascript.js", oDocument);  
         }  
      ); 

This works perfectly.
But I am still looking for authentic way of doing the same
0
Rumen
Telerik team
answered on 28 Apr 2009, 02:21 PM
Hello Subodh,

By default RadEditor removes all script tags to prevent the execution of malicious content in it. You can easily disable the content filter responsible for the <script> tags stripping by setting the line below via the codebehind:

RadEditor1.DisableFilter(EditorFilters.RemoveScripts);

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
Subodh
Top achievements
Rank 2
answered on 29 Apr 2009, 03:59 AM
Thanks for the reply; but the question remains same how to add the script file?

I want to add javascript file reference in head tag of rad editor's iframe's document.
0
Rumen
Telerik team
answered on 01 May 2009, 03:08 PM
Hi Subodh,

The simplest way is to use Full HTML Page Editing of RadEditor as it is demonstrated in this live example: Full HTML Page Edit.

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
Cary Abramoff
Top achievements
Rank 1
answered on 10 Jun 2011, 10:49 AM
I have same issue.
After reading this post I was quite disappointed.
Rumen's answer is a NON-ANSWER, as if to tell Subodh to go away.
I tried Subodh's solution but it did not work for me.
So two people who gave parital, out of context posts end up personifying the old adage, "haste makes waste"
0
Rumen
Telerik team
answered on 15 Jun 2011, 01:06 PM
Hi Cary,

Subodh's solution works as expected. You can see how it works in the following video: http://screencast.com/t/YI6rPgc6X. For your convenience I have attached my test page.

Another approach is to register the scripts in the head of the page with RadEditor and set the ContentAreaMode property to DIV. This will render the content area of RadEditor as an editable DIV element which is part of the current page and the scripts will be accessible in the RadEditor's body as well.

I also logged your request in our PITS system and if more users vote for it we will consider implementing it for a future version of the control. Here you can find the PITS Issue: Public URL.

Best regards,
Rumen
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Cary Abramoff
Top achievements
Rank 1
answered on 15 Jun 2011, 07:51 PM
Hi,

I received your email pointing to this post. That is very much appreciated. I got Subodh's solution working right away but in my case I was trying to get colorbox.js plugin working.

The radeditor, sometimes, in some browsers, displayed my images as lightbox shows and othertimes, in other browsers, did not. I use many radeditors in my site, and I needed a rock solid solution.

... so unfortunately I could not rely upon the radeditor and lightbox/colorbox plugin due to composability issues. 

The radeditor is a great product as it is what brought me to Telerik in the first place 2 years ago and for asp.net development I could never imagine using another product. I was an obout suite refugee and the Telerik experience blew them away and saved my business model.

That being said I am now trying to move away from asp.net all together in favor of pure amazon s3 jquery UI development. asp.net scaling is a nightmare in the cloud!

My final solution to the scripts issue was to use iframes.

Love those iframes!

Cary
Tags
Editor
Asked by
Subodh
Top achievements
Rank 2
Answers by
Subodh
Top achievements
Rank 2
Rumen
Telerik team
Cary Abramoff
Top achievements
Rank 1
Share this question
or