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

[Solved] Problem with inserting script to editor content.

2 Answers 125 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Max asked on 27 May 2008, 04:57 PM
I have a problem with inserting script to editor content (for google optimizer).

I created some button with this action:

Telerik.Web.UI.Editor.CommandList["AddGoogleOptimizer"] = function(commandName, editor, args)
{
var currentSelectedHtml = editor.getSelectionHtml();

currentSelectedHtml = String.format("<script>utmx_section(\"Section\")<\/script>{0}</noscript>", currentSelectedHtml);

editor.pasteHtml(currentSelectedHtml);
};


Also I disabled RemoveScripts filter (radEditor.DisableFilter(EditorFilters.RemoveScripts)),  but in editor content appear only selected html without any tags (IE 7).

I need to insert the following code:

<script>utmx_section('Section')</script>

SelectedContent

</noscript> 


Is there a way to resolve this problem?

2 Answers, 1 is accepted

Sort by
0
Max
Top achievements
Rank 1
answered on 28 May 2008, 11:49 AM

I made some changes:

currentSelectedHtml = String.format("&nbsp;<script>utmx_section(\"Section\")<\/script>{0}</noscript>", currentSelectedHtml);

Now I have following result: <script>utmx_section("Section")<script>SelectedHTML

Is it possible to prevent removing of </noscript> when switching to html mode?

PS: I tried to use <noscript>{0}</noscript> section, but its not working in IE7, in result there is no text between tags: <noscript></noscript>

0
Rumen
Telerik team
answered on 28 May 2008, 04:05 PM
Hello Max,

This is a browser behavior. You should put some content before the <script> tag in order to paste it - in other case the browser will strip it during the paste. For example you can put a simple &nbsp; entity, e.g.

<telerik:RadEditor ID="RadEditor1" runat="server">
<Tools>
<telerik:EditorToolGroup>
    <telerik:EditorTool Name="AddGoogleOptimizer" />
    <telerik:EditorTool Name="modulemanager" />
</telerik:EditorToolGroup>
</Tools>
</telerik:RadEditor>
<script type="text/javascript">
Telerik.Web.UI.Editor.CommandList["AddGoogleOptimizer"] = function(commandName, editor, args)
{
    var currentSelectedHtml = editor.getSelectionHtml();

    currentSelectedHtml = String.format("&nbsp;<script>utmx_section(\"Section\")<\/script>{0}</noscript>", currentSelectedHtml);

    editor.pasteHtml(currentSelectedHtml);
};
</script>


Kind regards,
Rumen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Editor
Asked by
Max
Top achievements
Rank 1
Answers by
Max
Top achievements
Rank 1
Rumen
Telerik team
Share this question
or