簡體   English   中英

RadEditor不斷刪除 <!doctype> 從HTML切換到設計時添加標記,如何停止此操作

[英]RadEditor keeps removing <!doctype> tag when switching from HTML to Design, how do I stop this

我在項目中使用RadEditor,但是當我在HTML編輯區域的頂部插入然后將視圖切換到“設計”並返回時。 標簽被刪除。 我想停止RadEditor進行此操作,而無需修改太多現有過濾器。

您可以在以下鏈接中嘗試

http://demos.telerik.com/aspnet-ajax/editor/examples/contentfilters/defaultcs.aspx

問題是您使用DIV模式而不是iFrame模式。 如果要使用DIV模式,則問題在於該頁面中已經有一個doctype,head,footer等。 頁面中不能存在兩次,瀏覽器會將其從頁面中刪除。

您可以使用iframe模式或下面的解決方案。

我使用的解決方案是用我的自定義標簽替換該標簽,當我從設計模式轉到編輯模式時,我將其替換,然后將其保存到數據庫時,我還將自定義標簽替換為普通標簽。 例如:

下面的代碼是我在項目中使用的示例(尚不包含doctype):

// Add the custom filter to the editor
function OnClientLoad(editor, args) {
    editor.get_filtersManager().add(new MyFilter());
}

// Replace the tags HTML does not expect twice
var tags = ["html", "body", "head", "title", "form", "textarea"];

MyFilter = function () {
    MyFilter.initializeBase(this);
    this.set_isDom(false);
    this.set_enabled(true);
    this.set_name("RadEditor filter");
    this.set_description("RadEditor filter description");
}

MyFilter.prototype =
{
    getHtmlContent: function (content) {
        var newContent = content;

        for (var i = 0; i < tags.length; i++) {
            var tag = tags[i];
            newContent = newContent.replace(new RegExp("<j" + tag, "gi"), "<" + tag);
            newContent = newContent.replace(new RegExp("<" + "/j" + tag + "", "gi"), "<" + "/" + tag + "");
        }

        return newContent;
    },
    getDesignContent: function (content) {
        var newContent = content;
        for (var i = 0; i < tags.length; i++) {
            var tag = tags[i];
            newContent = newContent.replace(new RegExp("<" + tag, "gi"), "<j" + tag);
            newContent = newContent.replace(new RegExp("<" + "/" + tag + "", "gi"), "<" + "/j" + tag + "");
        }
        return newContent;
    }
}
MyFilter.registerClass('MyFilter', Telerik.Web.UI.Editor.Filter);

並從編輯器獲取HTML並替換新標簽:

function GetEditorHtmlCall() {
    var html = $find("RadEditor1").get_html(true);

    for (var i = 0; i < tags.length; i++) {
        var tag = tags[i];
        html = html.replace(new RegExp("<" + tag, "gi"), "<j" + tag);
        html = html.replace(new RegExp("<" + "/" + tag + "", "gi"), "<" + "/j" + tag + "");
    }

    return html;
}

上面的代碼將替換下面的示例。 在設計模式下,您具有jhtml標記,在html模式下,您具有html標記。 保存時,將jhtml標記轉換回html,因此在數據庫中很好用:

<html></html> to <jhtml></jhtml>

希望這能為您提供所需的解決方案。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM