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

[Solved] RadEditor attachEventHandler onkeydown CTRL+S shows Save As dialog in Firefox

1 Answer 172 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Craig Somers
Top achievements
Rank 1
Craig Somers asked on 14 Dec 2009, 04:40 PM
Hi There,

I have a RadEditor control on my page with the following lines of client side code:

editor.attachEventHandler("onkeydown", OnKeyDown);

function OnKeyDown(e)
{
  if (e.ctrlKey === true && String.fromCharCode(evtobj.keyCode) === "S")
  {
     alert("Custom Save");
     return stopPropagation(e);
  }
}

function StopPropogation(e)
{
    e.cancelBubble = true;
    e.returnValue = false;

    if (e.stopPropagation)
    {
        e.stopPropagation();
        e.preventDefault();
    }

    return false;
}

This works in IE and Firefox, except that in Firefox the "Save As" dialog appears, no matter what i try. If i add a debugger line in my OnKeyDown method, the breakpoint gets hit AFTER the SaveAs dialog appears - so it seems that the attachEventHandler method of telerik adds the event too late or executes my code too late?

Applying my code to a test HTML page with:

document.onkeydown = OnKeyDown;

...works fine.

What is telerik RadEditor doing differently? What can I do to work around this?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 15 Dec 2009, 03:54 PM
Hello Craig,

Please note that you cannot compare RadEditor with the document object of the page because the content area of RadEditor is another document. The problem is a browser behavior is related to the alert() function.

You can verify this by testing the code below:

<telerik:radeditor runat="server" ID="RadEditor1" Skin="Forest" OnClientLoad="OnClientLoad">
    <Content>sample content</Content>
</telerik:radeditor>
<script type="text/javascript">
function OnClientLoad(editor)
{
    editor.attachEventHandler("onkeydown", OnKeyDown);
}
 
function OnKeyDown(e)
{
  if (e.ctrlKey === true && String.fromCharCode(e.keyCode) === "S")
  {
     dump("Custom Save");
     $telerik.cancelRawEvent(e);
          
  }
}
function dump(text)
    {
        $get("dbd").innerHTML = " " + text;
    }
</script>
<div id="dbd" style="font-family: Verdana; font-size:10px;"> </div>

 You will see that after removing the alert then Firefox does not launch its Save As dialog.


Kind regards,
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.
Tags
Editor
Asked by
Craig Somers
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or