【问题标题】:RadEditor scrolls to top after pasting the contents粘贴内容后 RadEditor 滚动到顶部
【发布时间】:2018-02-16 09:39:48
【问题描述】:

我正在使用 Telerik RadEditor。

问题:

在将内容粘贴到 Telerik Radeditor 时,编辑器会滚动到顶部。所以,我搜索了互联网和 Telerik 论坛,但没有运气。最后,我修复了以下代码。

RadEditor 服务器端控制代码:

     <telerik:RadEditor 
                        ID="E" 
                        runat="server" 
                        Width="100%" 
                        AllowScripts="true" 
                        AllowPaging="true" 
                        EnableResize="false"
                        NewLineMode="P" 
                        OnClientLoad="OnClientLoad" 
                        OnClientModeChange="E_OnClientModeChanged" 
                        EditModes="Design,Html"
    StripFormattingOptions="Span,MsWordRemoveAll,CSS,Font,ConvertWordLists" 
                      OnClientPasteHtml="radEditorControl_OnClientPasteHtml" 
                      OnClientSelectionChange="OnClientSelectionChange">


</telerik:RadEditor>

以下是修复后的 Javascript 代码:

//Event on pasting the content into the RadEditor. Fixing the scrolling issue on pasting the content.

        var isPasted = false;

        function radEditorControl_OnClientPasteHtml(editor, args) {
            if (editor != undefined)
                isPasted = true;
        }

function OnClientSelectionChange(editor, args) {
            if (isPasted != undefined && isPasted == true && editor != undefined) {
                isPasted = false;
                editor.setFocus();
                var iframeElement = editor._contentAreaElement; // the DOM element for the iframe;

                if (iframeElement) {
                    //Get the iFrame cursor position.
                    var _focusNode = iframeElement.contentWindow.getSelection().focusNode;

                    if (_focusNode != undefined) {
                        //Focus node is not an element, get the previous element sibling
                        if (_focusNode.nodeType != 1) {
                            if (_focusNode.previousElementSibling != undefined)
                                _focusNode = _focusNode.previousElementSibling;
                            else
                                _focusNode = _focusNode.parentNode;
                        }

                        //Insert a div near focusNode(cursor) of the iFrame contentWindow.
                        var timeStamp = new Date().getUTCMilliseconds();
                        var _id = "scrollArea_" + timeStamp;

                        var focusElement = jQuery('<input type="text" id="' + _id + '" name="' + _id + '" onfocus="alert();" />').insertAfter(_focusNode)[0];

                        setTimeout(function () {
                            if (focusElement != undefined) {
                                focusElement.focus({ preventScroll: true });
                                focusElement.select();
                                var range = editor.getSelection().getRange(true); //returns an object that represents a restore point.
                                editor.getSelection().selectRange(range);
                                if (range != undefined && range.collapse !=undefined)
                                    range.collapse(true);

                                jQuery(focusElement).replaceWith("");
                            }
                        }, 50);
                    }
                }
            }
        }

以上代码在 IE 和 Chrome 中有效,但在 Firefox 中无效,因为我绑定的输入元素没有触发 focus()。

如果有其他方法可以解决在 RadEditor 中粘贴时的滚动问题,请告诉我。

【问题讨论】:

    标签: javascript firefox telerik radeditor


    【解决方案1】:

    我知道在旧版本的 RadEditor 中存在这样的问题。我的建议是尝试最新版本,您可以在 https://demos.telerik.com/aspnet-ajax/editor/examples/overview/defaultcs.aspx 进行测试。如果问题仍然存在,请在 Telerik AJAX 论坛或通过支持票务系统给我们留言,我们将对其进行深入调查。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-04
      • 1970-01-01
      • 2017-11-29
      • 2014-12-25
      • 2023-04-11
      • 1970-01-01
      相关资源
      最近更新 更多