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

Javascript in MOSS radEditor

40 Answers 700 Views
WebParts for SharePoint
This is a migrated thread and some comments may be shown as answers.
John Way
Top achievements
Rank 1
John Way asked on 09 Aug 2007, 12:42 PM
Is there a work-around or configuration setting to allow the follwoing in the MOSS Premium radEditor
  • inline javascript and / or onClick events that call javascript in the
  • style commands on DIV's
  • iframes

Thanks,

John

40 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 09 Aug 2007, 12:50 PM
Hi John,

I am not quite sure what exactly you want to achieve, however you can use Javascript in RadEditor's content are in certain scenarios only. To enable Javascript, you need to do the following:

  • RadEditor in WebPart:
    Set (add if not present) the AllowScripts property to true in ConfigFile.xml
  • RadEditor in WCM:
    Set (add if not present) the AllowScripts and AllowSpecialTags properties to true in ConfigFile.xml
  • SharePoint forms scenario (Lists, Wikis, Blogs, etc.)
    You cannot use Javascript in RadEditor in such scenario. There RadEditor does not have control over the presentation view which means that we cannot control the output when it is not in edit mode.



Best wishes,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
John Way
Top achievements
Rank 1
answered on 09 Aug 2007, 02:05 PM

The changes you recommended did not work. For my current task, I am trying to create an inline, sized, javascript  popUp Window in a WCM radEditor field control.
I already had the AllowSpecialTags attribute set to true in the Page Layout's radE:RadHtmlField control to allow flash content. That was working fine. I added both tags to the config.xml anyway, per your instructions, and received a runtime error.
Configuration File provided is not valid. Invalid entries: AllowSpecialTags
I removed the AllowSpecialTags property from the config.xml and the error went away. However, when I try to add a javascipt call using the radEditor, the content gets stripped when I publish the page.

<a href="#" OnClick="window.open('http://www.google.com', 'Google'', 'height=130, width=160', false); return false;">Google</a>  
 
get changed to
<a href="#">Google</a>  

I also tried adding the AllowScripts to the radE:radHtmlField control, but that was not allowed either.

Here is my config.xml code:
<?xml version="1.0" encoding="utf-8" ?> 
<!-- ==============================================================================================  
    Config File valid structure:  
    <configuration> 
    <property>...</property> 
    ...  
        <property> 
            <item>...</item> 
            <item>...</item> 
            ...  
        </property> 
        ...  
    </configuration> 
=============================================================================================== --> 
<configuration> 
  <property name="AllowScripts">True</property> 
  <property name="AllowThumbGeneration">True</property> 
  <property name="ConvertToXhtml">True</property> 
  <property name="EnableDocking">False</property> 
  <property name="ShowHtmlMode">True</property> 
  <property name="ShowPreviewMode">False</property> 
  <property name="StripAbsoluteAnchorPaths">False</property> 
  <property name="StripAbsoluteImagesPaths">False</property> 
  <property name="ToolbarMode">ShowOnFocus</property> 
  <property name="ToolsWidth">800px</property> 
</configuration> 
0
Georgi Tunev
Telerik team
answered on 09 Aug 2007, 03:15 PM
Hello John,

I would like to apologize for misleading you in my previous reply. You need to set the AllowScripts property to true in ConfigFile.xml and AllowSpecialTags = true in the the current page using SharePoint Designer - AllowSpecialTags cannot be set via ConfigFile.xml.

Once again, sorry for the trouble.



Greetings,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
John Way
Top achievements
Rank 1
answered on 09 Aug 2007, 03:48 PM
No problem, however...
After making the changes, I still can't add javascript or onClick calls. The script is still getting stripped. (see my last post for details)

Is there something else I'm missing?

Thanks,
John
0
Accepted
Georgi Tunev
Telerik team
answered on 10 Aug 2007, 12:26 PM
Hello John,

We (me and one of our RadEditor for MOSS developers) checked your code and it occurs that it must be inserted in a little bit of different way than the one you are using. The procedure is a little cumbersome and we will do our best to improve the situation in one of the following updates. Unfortunately at this point it must be followed step-by-step as otherwise the MOSS itself will clear the Javascript.

Here is how to add your Javascript step-by-step:
  1. set the AllowScripts property to true in ConfigFile.xml and AllowSpecialTags = true in the the current page using SharePoint Designer
  2. Do not add your Javascript in the OnClick property. You must add it in a separate <script> block.
  3. Add an ID to your link
  4. After the link's declaration, add a <script></script> block with the needed Javascript, e.g: document.getElementById('yourID').onclick=function (){yourFunction};

Note that the <script> block must be placed on a single line - do not press Enter, otherwise the MOSS will remove the script tags.

For convenience I've attached to this thread a small movie that shows how to insert your code in RadEditor for MOSS.
Let me know if you experience any problems with the approach.




All the best,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
John Way
Top achievements
Rank 1
answered on 10 Aug 2007, 01:06 PM
A video that walks me through the solution?? You Guys ROCK! Finally a company that actually lives by their slogan. This truly was "more than expected".

Thanks,
John W.
Spartanburg, SC
0
Bob
Top achievements
Rank 1
answered on 05 Feb 2008, 09:25 PM
Hi,

I don't see the spiffy movie.  It would be helpful.

Thanks

Bob.
0
John Way
Top achievements
Rank 1
answered on 05 Feb 2008, 10:06 PM
It's in the thread above. It's called MossJavascript.zip
0
Bob
Top achievements
Rank 1
answered on 06 Feb 2008, 02:33 PM
duh...

Thanks - I was having a slow day.

In essence...
<a id="PrintIt" href="#">
    Where Am I 
</a>
<script type="text/javascript">document.getElementById('PrintIt').onclick=function(){alert('I Is Here')};</script>

0
John Wilson
Top achievements
Rank 1
answered on 04 Jun 2008, 01:53 PM
Jon,

I have the same issue using vs. 4.5.3 of the Rad Editor for MOSS.  Do  I still need to use the same work around?  Has this changed in v. 5.0.0?

Thanks,

John Wilson
0
Lini
Telerik team
answered on 04 Jun 2008, 04:27 PM
Hi John,

Yes, you still need to use this workaround in version 5.0. As we said previously, the problem is actually in a MOSS content filter and not the editor itself. The only way to have scripts in the content is to encode them before the content is saved in the SharePoint field. This way the script will not be stripped. I don't think that we will be able to fix this in a future editor release.

Sincerely yours,
Lini
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Dave
Top achievements
Rank 1
answered on 21 Jul 2008, 03:37 AM

0
laks
Top achievements
Rank 1
answered on 08 May 2009, 06:25 PM
I am trying the trial version.
I have done exactly as in the video and have taken care of the other installation instructions.
I am however loosing the javascript the moment I checkin or publish the page.
The javascript seems to be persistent as long as I toggle betweent he design,html and presentation  views
Any thing else that needs to be done to get the javascript to persist in the published version..

Thank you
0
Thiyagarajan
Top achievements
Rank 1
answered on 11 May 2009, 12:31 PM

Hi,

         I am facing the same issues.
       
          Iam using Rad Editor 4.5.3.2 for my Organisation. When i save my content with Javascript , the savascript is stripped.
          I tried all the possible way given by you but it doesnt work .

          I cant include the script pag by page since mine is a MOSS application.


          I kindly request you to help me to get rid of this issue.


          My Contact :  +91 9916149227

Thanks and Regards

Thyagu

 

       

0
Stanimir
Telerik team
answered on 11 May 2009, 01:02 PM
Hello Thiyagarajan,

Could you please confirm that you are not using the RadEditor for MOSS in form scenario such as List, Wiki, Blog? If this is the case you should know that after sending the content to the SharePoint server some content filters are applied and they are stripping the javascript tags. Unfortunately RadEditor has no control over these filters.


Kind regards,
Stanimir
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
laks
Top achievements
Rank 1
answered on 11 May 2009, 05:24 PM
Hi Stanmir,
Is it becuase I am using a trial version to evaluate, that I am not getting a response! :)
Just an FYI - I am not using the lists or wikis in MOSS.
I am using the RadEditor for MOSS, just like displayed in the video...
The script gets stripped...
It is a simple test trying to replace the HTML Placeholder with RadEditor..
Look forward to hearing for some resolution! :)

Thank you
laks

0
Thiyagarajan
Top achievements
Rank 1
answered on 12 May 2009, 09:55 AM

Hi,



                        Thank you for your quik response.
                        Iam using the Rad in Wiki and Create Page.        These are the Places it gets stripped.
                          If this is Stripped by MOSS. Do you have any info how i can over come the same.

 

regards

Thyagu

0
Stanimir
Telerik team
answered on 13 May 2009, 10:51 AM
Hi Thiyagarajan,

Unfortunately in this moment we do not know of existing work around. This is MOSS issue and it is not related to the RadEditor for MOSS control.

Greetings,
Stanimir
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
Shishir
Top achievements
Rank 1
answered on 08 Jun 2009, 06:27 AM
Hi,

I am trying to enable javascript support like you said by setting "AllowSpecialTags" to be true in telerik:RadHtmlField control in layout page and adding AllowScripts in configfile.xml. I am using RAD MOSS Editor v 5.2.1. I type the javascript in a single line and still it gets stripped on saving the page. 

Pagelayout
                   <telerik:RadHtmlField FieldName="PublishingPageContent" runat="server" AllowSpecialTags="true" />

configfile.xml in C:\Program Files\Common Files\Microsoft Shared\web server extensions\wpresources\RadEditorSharePoint\5.4.1.0__1f131a624888eeed\Resources
<configuration>
 <property name="ToolbarMode">ShowOnFocus</property>
 <property name="ToolsWidth">680px</property> 
        <property name="AllowScripts">true</property>
</configuration>

Regards,
Shishir 

0
Lini
Telerik team
answered on 08 Jun 2009, 06:51 AM
Hi Shishir,

Is your script in a <script> tag or inline (e.g. in a href or onclick attribute of an anchor)? Please make sure that all scripts are in a <script> tag. If possible, show us a sample of your content before/after the script is stripped.

Sincerely yours,
Lini
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
Shishir
Top achievements
Rank 1
answered on 08 Jun 2009, 08:20 AM
Hi Lini,

Here is the code I am trying to save

Test Scripts
<script> alert('hello');</script>

Once I publish, the content changes to just

Test Scripts

I have changed the AllowScripts property in configfile.xml and the AllowSpecialTags attribute in layout page rad editor control to true.

Shishir

0
Stanimir
Telerik team
answered on 08 Jun 2009, 08:49 AM
Hello Shishir,

What you should know is that you can see the code that is sent to the MOSS site when you toggle between Design and HTML mode. Could you confirm that your javascript is executed when you toggle between modes?

Also when you save the content to the MOSS site some SharePoint's filters are applied over it. These filters are responsible for stripping the javascript code. Unfortunately RadEditor can not control this SharePoint functionality and there is no known work around for it.


Kind regards,
Stanimir
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
Shishir
Top achievements
Rank 1
answered on 08 Jun 2009, 09:02 AM
Hi Stanimir, 

When I switch between design and code mode I still see the script code. However the code is not executed. I can switch multiple times without loosing the script. Only once I publish it or check it  in the script tag is stripped. The tag and code are completely in one line.

Why I ask is because some people on this site seem to have been able to save script changes. Like the video you shared shows the saving working but when I tried exact same code it did not work on my SharePoint server. I am also using publishing template.

0
Stanimir
Telerik team
answered on 08 Jun 2009, 10:20 AM
Hello Shishir,

The javascript is not executed because there is a content filter, provided by Telerik, which stops the javascript from executing. How ever if you can see the javascript code in Html mode this means that it is sent to the server and is stripped on it. Again RadEditor has no control over this.


Regards,
Stanimir
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
Archana
Top achievements
Rank 1
answered on 04 Jul 2009, 12:39 PM
Hi Stanimir

I have recently upgraded my radEditor for MOSS from 5.4.0.0 to 5.4.1.0.
But I am facing the issue with script tag added for the html link as following.
The tags which i am adding through a button is :
    <div><a href="/links/redirectlink.aspx?id=yahoo mail.aspx" class="new-window-left" id="47200917594425" title="yahoo mail" target="_blank">yahoo mail</a>
<script>document.getElementById("47200917594425").onclick=function(){ExnLinkTrack(this);}</script>
</div>

The problem is : While checking in the page from html view of radEditor the script tag is retained on editing the page next time,  but while checking in the page from design view of radEditor the script tag gets stripped off on editing the page next time.

Please note that i have set both the properties - "AllowScripts" in configFile and "AllowSpecialTags" in page as true.

I was not facing the same problem with version 5.4.0.0.

Is there any solution for this?

Regards,
Archana

0
Stanimir
Telerik team
answered on 07 Jul 2009, 10:59 AM
Hi Archana,

This week we will release the new version of RadEditor for MOSS 5.5.0. The issue will be fixed in it. You can find upgrade instructions in the following help article http://www.telerik.com/help/aspnet-ajax/upgrade_to_a_newer_version_of_radeditor_for_moss.html.

Also keep in mind that you can not enter javascript in form scenarios, such as list, wiki, blog ... .  Here is the help article that describes the usage of scripts in RadEditor http://www.telerik.com/help/aspnet-ajax/scripts-in-radeditor.html


All the best,
Stanimir
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
Archana
Top achievements
Rank 1
answered on 07 Jul 2009, 01:22 PM

Hi Stanimir,

 

Thanks for the prompt reply.

However there is one more issue i am encountering for the version 5.4.1.0: 
 I have added a custom button in radEditor toolbar.
On click of that button I want a script to be generated and pasted in the html view.
Say for e.g. 

    <script>
    var strTitle="Title";
    alert(strTitle);
    </script>

In the function for that custom button in MossEditorTools.js file, i am writing following code :
    editor.pasteHtml('<script>var strTitle="Title";alert(strTitle);</script>')

But on switching to html mode it does not show the script tag at all, i.e. if i modify the code as 
    editor.pasteHtml('<div><script>var strTitle="Title";alert(strTitle);</script></div>')
then in html view it will only show : <div></div>
The script tag is totally stripped.

Please not that i have set both the properties : "AllowScript" in ConfigFile and "AllowSpecialTags" in page as true.
Any clue on how to address this ?

Regards,
Archana

0
Stanimir
Telerik team
answered on 09 Jul 2009, 11:31 AM
Hi Archana,

The described issue is a known Internet Explorer browser behavior. I can suggest you the following work around. what you need to do is add a &nbsp; before the <script> tag.
editor.pasteHtml('&nbsp;<script>var strTitle="Title";alert(strTitle);</script>'); 

I hope this helps.



All the best,
Stanimir
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
Archana
Top achievements
Rank 1
answered on 10 Jul 2009, 05:30 AM
Hi Stanimir,

Thanks a lot. It worked for me.
However, in js file i have written code for the button to copy following text in htmlview :
    <script type="text/javascript"> var strEmail1="abc_xyz";var strEmail2="@";var strEmail3="def.com";var strTitle="Archana Kanth";document.write("<a href=mailto:"+ strEmail1 + strEmail2 + strEmail3 + ">" + strTitle + "</a>");</script>

But instead its copying following text in the html view on clicking that button :
    <script type="text/javascript"> var strEmail1="abc_xyz";var strEmail2="@";var strEmail3="def.com";var strTitle="Archana Kanth";document.write("<a href=mailto:" originalAttribute="href" originalPath="mailto:"" + strEmail1 + strEmail2 + strEmail3 + ">" + strTitle + "</a>");</script>

The text in the bold is appended by itself in the script tag and this is creating problem in the page.

Any solution to avoid the appending text in the script?

Regards,
Archana
0
Stanimir
Telerik team
answered on 10 Jul 2009, 12:10 PM
Hi Archana,

Unfortunately this is again browser behavior of MS Internet Explorer. I tested the issue in FireFox and the javascript worked fine. Unfortunately currently we do not know of any workarounds for this. We will inform you if we find a fix for this.


Sincerely yours,
Stanimir
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
Archana
Top achievements
Rank 1
answered on 20 Jul 2009, 05:01 AM
Hi Stanimir,

I am using radEditor version 5.5.0.0.  
I have activated the radEditor feature for using it in Sharepoint lists as well.
But in lists fields, it strips the script tag.
I have set "AllowScripts" property true in both ConfigFile.xml and ListConfigFile.xml.
Am I missing something to render script tags in list field?

Regards,
Archana
0
Stanimir
Telerik team
answered on 20 Jul 2009, 08:07 AM
Hi Archana,

You cannot use Javascript in RadEditor in SharePoint forms scenario (Lists, Wikis, Blogs, etc.). There RadEditor does not have control over the presentation view which means that we cannot control the output when it is not in edit mode.

Greetings,
Stanimir
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
Nate
Top achievements
Rank 1
answered on 28 Oct 2010, 06:38 PM
I am sort of confused here why it is that Telerik folks keep saying it is MOSS or WSS3 that is stripping the special chars and script tags. Maybe there is something I am missing here but if I create a custom control and use a basic asp.net textbox to fill the multiline text field type with the text from the textbox the special stuff is NOT stripped. If however I swap the textbox for a MossRadEditor ver5.8.0.0 it strips the special stuff out. Below is the FieldControl class which works fine when using the textbox(commented in the value fill and swapped for the radeditor).

public class WERCRichTextFieldControl : BaseFieldControl
    {        
  
        private MOSSRadEditor editCtrl;
        protected TextBox ScriptTextBox;
        protected Literal litMsg;
        protected PlaceHolder EditorPlaceHolder;
  
        protected override string DefaultTemplateName
        {
            get
            {
                return "WERCRichTextField";
                //return base.DefaultTemplateName;
            }
        }
  
  
        protected override void RenderFieldForDisplay(HtmlTextWriter output)
        {
            RenderChildren(output);
        }
  
        protected override void CreateChildControls()
        {
            if (this.Field == null || this.ControlMode == SPControlMode.Display || this.ControlMode == SPControlMode.Invalid)
                return;
  
            base.CreateChildControls();
  
            if (ControlMode == SPControlMode.Edit || ControlMode == SPControlMode.New)
            {
                ScriptTextBox = (TextBox)TemplateContainer.FindControl("ScriptTextBox");
                litMsg = (Literal)TemplateContainer.FindControl("litMsg");
                EditorPlaceHolder = (PlaceHolder)TemplateContainer.FindControl("EditorPlaceHolder");
                editCtrl = new MOSSRadEditor();
                editCtrl.AllowScripts = true; 
                //--also added allowscripts in both the ListConfigFile.xml
                //--and ConfigFile.xml                
                EditorPlaceHolder.Controls.Add(editCtrl);
                if (!this.Web.CurrentUser.IsSiteAdmin)
                {
                    ScriptTextBox.Visible = false;
                    ScriptTextBox.ReadOnly = true;
                    litMsg.Text = "Only Site Administrators can add Script<br />";
                }
            }
        }
  
        public override object Value
        {
            get
            {
                EnsureChildControls();
                //---see right here if I were using the ScriptTextBox 
                //---it has no problem saving anything that I plug in and the
                //---base MultiLineTextField type is not stripping html content 
                //return ScriptTextBox.Text;
                return editCtrl.Content;
            }
            set
            {
                EnsureChildControls();
                base.Value = value;
                ScriptTextBox.Text = value.ToString();
                editCtrl.Content = value.ToString();
            }
        }
    }
0
Stanimir
Telerik team
answered on 01 Nov 2010, 02:13 PM
Hi Nate,

Thank you for the provided information, how ever the way your control is written I do not think that it will support SharePoint's automated features, such as automatic update of reusable content or automatic update of links etc. The price of supporting this features is that the content is modified by the SharePoint content filters which strip a lot of "invalid" (according to them) code.

Sincerely yours,
Stanimir
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nate
Top achievements
Rank 1
answered on 01 Nov 2010, 05:02 PM
Thanks for your response; however, I really am asking a question. Sorry I didn't word that more directly.
I need to get the special characters into a rich text field. I know I can do it if I create a custom field type based on the same type the OOTB rich text box uses and just use my own asp.net textbox as shown from the previous post. That doesn't work though with the MOSSRadEditor. Maybe the answer here is that I have to use the basic radeditor and not the MOSSRadEditor? How exactly does the MOSSRadEditor tie into the sharepoint libraries? Does it call internal sharepoint stuff before the .content of the MOSSRadEditor is handed back? 
 
 
0
Stanimir
Telerik team
answered on 03 Nov 2010, 09:35 AM
Hello Nate,

Does it call internal sharepoint stuff before the .content of the MOSSRadEditor is handed back? - Yes RadEditor uses SharePoint API in order to display and save the content. If you open an official support ticket and you have valid license information I will provide you with the source code of the control and you will be able to see the exact implementation.


Greetings,
Stanimir
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nate
Top achievements
Rank 1
answered on 03 Nov 2010, 06:06 PM
In the last post I had the question "Maybe the answer here is that I have to use the basic radeditor and not the MOSSRadEditor?"
If I were to use the regular radeditor vs. the sharepoint version what major losses would I have in functionality?
Or would it be better to like you said take the source code for the MOSSRadEditor and rewrite it so that it doesn't leverage the sharepoint stripping engine before it inserts its value into the field? Or do you guys already have a version or hotfix like that? It just sounds like not everyone cares to allow sharepoint to strip the potentially bad code blocks. It seems like it would be an easy enough thing to set up as a configurable choice for MOSSRadEditor.

0
Stanimir
Telerik team
answered on 04 Nov 2010, 01:28 PM
Hello Nate,

If you use the regular ASP.NET AJAX RadEditor, you will loose the filebrowser based dialogs, such as ImageManager, DocumentManager etc. In RadEditor for MOSS there is a specially designed content provider, which works with SharePoint libraries.

Regards,
Stanimir
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Nate
Top achievements
Rank 1
answered on 04 Nov 2010, 05:10 PM
Oh yea. Totally didn't think about that.. BUT arn't those just pages that are installed into layouts or are resources? Can't I just add them as tools to the regular rad editor as long as I have the MOSSRadEditor installed in that same sharepoint web?
If so how do I point to those?
0
Stanimir
Telerik team
answered on 05 Nov 2010, 09:14 AM
Hello Nate,

Actually these are the same dialogs the think that is different is the content provider, which is embedded in the MOSS RadEditor. Review the following blog post: Using the RadFileExplorer for ASP.NET AJAX in a MOSS web application. Also review the following online demo: Editor / Custom File Dialogs Content Provider

Sincerely yours,
Stanimir
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
WebParts for SharePoint
Asked by
John Way
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
John Way
Top achievements
Rank 1
Bob
Top achievements
Rank 1
John Wilson
Top achievements
Rank 1
Lini
Telerik team
Dave
Top achievements
Rank 1
laks
Top achievements
Rank 1
Thiyagarajan
Top achievements
Rank 1
Stanimir
Telerik team
Shishir
Top achievements
Rank 1
Archana
Top achievements
Rank 1
Nate
Top achievements
Rank 1
Share this question
or