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

Default font settings

1 Answer 131 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Harsh
Top achievements
Rank 1
Harsh asked on 13 May 2013, 05:32 AM
I have set the default font setting using the shown below js
The script works fine and can see intended font changes when I switch to preview mode
but in HTMLedit view intended HTML font tags and attribute are not seen
and hence when I get the content of Radeditor using

rdEditor.Content property it does not include the default settings(font attributes ) and intended font changes 

rdEditor.OnClientLoad = "OnClientLoad";
       string js = @"
   <script language='javascript'>
       function OnClientLoad(editor, args) {
           setTimeout(function()
           {
 
                 var style = editor.get_contentArea().style;
                 style.fontFamily= 'Calibri';
                 style.fontSize= 11 + 'pt';
                 style.color = '#1f497d';
 
           }, 100);
       }
   </script>";
       Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "myscriptkey", js);

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 13 May 2013, 09:49 AM
Hello,

Indeed, the code that you use applies font family, size and color to the content area of the editor. This has nothing to do, however, with the contents loaded in this content area.

What you can do is to wrap the contents in some span tag with the desired font formatting.
You can use the following code solution to wrap the initial content or the empty content of RadEditor in a span tag with Calibri 11px, e.g.

<telerik:radeditor runat="server"OnClientLoad="OnClientLoad"ID="RadEditor1">
</telerik:radeditor>
<script type="text/javascript">
function OnClientLoad(editor) {
  setTimeout(function() {
   var tool = editor.getToolByName("RealFontSize");
   tool.set_value("11px");
   var args = newTelerik.Web.UI.EditorCommandEventArgs("RealFontSize", null,     "11px");
editor.fire("RealFontSize", args);
editor.fire("FontName", { value: "Calibri"});
}, 0);
}
</script>


Another way is to wrap the obtained content on the server in a span tag having the desired font-size style in pixels, e.g.

RadEditor1.Content = "<span style='font-family: Calibri;font-size: 11px;'>" + RadEditor1.Content + "</span>";
 

Best regards,
Rumen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Editor
Asked by
Harsh
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or