C#結(jié)合JS修改解決KindEditor彈出層問(wèn)題
問(wèn)題現(xiàn)象
KindEditor 是一款出色的富文本HTML在線編輯器,關(guān)于編輯器的詳細(xì)介紹可參考我的文章《C# 將 TextBox 綁定為 KindEditor 富文本》,這里我們講述在使用中遇到的一個(gè)問(wèn)題,在部署到某些 WEB 應(yīng)用項(xiàng)目中,點(diǎn)擊類似彈出層功能時(shí),只顯示了遮罩層,而內(nèi)容層則定位無(wú)法正確顯示,下面所列是一些有關(guān)彈出層的功能,正確顯示如下圖:



但某些時(shí)候,會(huì)只顯示遮罩層,無(wú)法顯示彈出層,如下圖:

原因分析
在瀏覽器顯示內(nèi)容中右擊審查元素(360極速,edge則為檢查元素),如下圖:

發(fā)現(xiàn)遮罩層輸出正常,為絕對(duì)定位,并設(shè)置正確了 left 、top、width、height 值,但排查到 css class 為 ke-dialog 的彈出層時(shí),發(fā)現(xiàn) position 定位缺失了 top 值,這應(yīng)該是彈出層問(wèn)題之所在。
范例運(yùn)行環(huán)境
操作系統(tǒng): Windows Server 2019 DataCenter
.net版本: .netFramework4.0 或以上
KindEditor version 4.1.7 (2013-04-21)
開發(fā)工具:VS2019 C#
解決問(wèn)題
修改 kindeditor.js
如下圖,我們發(fā)現(xiàn)遮罩層的 z-index 值為 811212,彈出層的 z-index 值為 811213:

因此打開 kindeditor.js 核心文件進(jìn)行查找修改,該文件存在于插件應(yīng)用的根目錄:

按 811213 進(jìn)行查找,發(fā)現(xiàn)如下圖代碼:

可試圖在 options 選項(xiàng)里增加初始的 top 屬性值為 '100px',保存文件再試。
C# 服務(wù)端更新
在我的文章《C# 將 TextBox 綁定為 KindEditor 富文本》里我們創(chuàng)建了 KindEditor 類,可修改類代碼,通過(guò)時(shí)間戳引入更新后的js版本,重寫后的代碼如下:
public class KindEditor
{
Page CurrentPage = null;
public KindEditor(object page)
{
if (page == null)
{
return;
}
CurrentPage = (Page)page;
}
public string init(string[] idList)
{
return init(idList, null);
}
public string init(string[] idList,Literal writeControl)
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
string timestamp= Convert.ToInt64(ts.TotalSeconds).ToString();
HtmlLink cssLink = new HtmlLink();
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Href = "/common/kindEditor/themes/default/default.css";
CurrentPage.Header.Controls.Add(cssLink);
HtmlLink cssLink2 = new HtmlLink();
cssLink2.Attributes.Add("rel", "stylesheet");
cssLink2.Href = "/common/kindEditor/plugins/code/prettify.css";
CurrentPage.Page.Header.Controls.Add(cssLink2);
HtmlGenericControl sc = new HtmlGenericControl("script");
sc.Attributes.Add("charset", "uft-8");
sc.Attributes.Add("src", "/common/kindEditor/kindeditor.js?v="+timestamp);
CurrentPage.Page.Header.Controls.Add(sc);
HtmlGenericControl sc2 = new HtmlGenericControl("script");
sc2.Attributes.Add("charset", "uft-8");
sc2.Attributes.Add("src", "/common/kindEditor/lang/zh_CN.js");
CurrentPage.Page.Header.Controls.Add(sc2);
HtmlGenericControl sc3 = new HtmlGenericControl("script");
sc3.Attributes.Add("charset", "uft-8");
sc3.Attributes.Add("src", "/common/kindEditor/plugins/code/prettify.js");
CurrentPage.Page.Header.Controls.Add(sc3);
string js = fLoadFromFile(CurrentPage.Request.PhysicalApplicationPath + "common/kindEditor/init.js", Encoding.Default);
HtmlGenericControl sc4 = new HtmlGenericControl("script");
foreach (string id in idList)
{
sc4.InnerHtml += js.Replace("{0}", id);
}
CurrentPage.Page.Header.Controls.Add(sc4);
return "";
}
public string LoadFromFile(string PathFile,System.Text.Encoding encodtype)
{
FileStream fs;
StreamReader newsfile;
String linec,x_filecon="";
fs=new FileStream(PathFile,FileMode.Open);
newsfile=new StreamReader(fs,encodtype);
try
{
linec=newsfile.ReadLine();
while(!(linec==null))
{
x_filecon+=linec+"\r\n";
linec=newsfile.ReadLine();
}
newsfile.Close();
fs.Close();
}
catch(Exception)
{
newsfile.Close();
fs.Close();
}
finally
{
newsfile.Close();
fs.Close();
}
return x_filecon;
}//LoadFromFile Function
}在 init 方法中生成時(shí)間戳變量 timestamp, 并在服務(wù)端 header 修改 sc.Attributes.Add("src", "/common/kindEditor/kindeditor.js?v="+timestamp); 的時(shí)間戳版引用,以便于調(diào)試修改和刷新。至此問(wèn)題解決。
小結(jié)
在調(diào)試成功完成后,可關(guān)閉時(shí)間戳版本引用方法以進(jìn)行緩存操作,防止每次都重新加載文件內(nèi)容。
關(guān)于彈出層顯示如果不修改代碼,還可以使用一種消極方法進(jìn)行操作,即點(diǎn)擊其全屏功能,如下圖:

全屏后兼容性比較好,未出現(xiàn)彈出層定位不準(zhǔn)的問(wèn)題,但如果在整體操作界面上來(lái)說(shuō),來(lái)回的切換全屏模式比較繁瑣。
到此關(guān)于修改解決 KindEditor 彈出層問(wèn)題就介紹到這里,感謝您的閱讀,希望本文能夠?qū)δ兴鶐椭?/p>
以上就是C#結(jié)合JS修改解決KindEditor彈出層問(wèn)題的詳細(xì)內(nèi)容,更多關(guān)于C# KindEditor彈出層的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#中讓控件全屏顯示的實(shí)現(xiàn)代碼(WinForm)
有時(shí)候需要讓窗口中某一塊的內(nèi)容全屏顯示,比如視頻播放、地圖等等。經(jīng)過(guò)摸索,暫時(shí)發(fā)現(xiàn)兩種可行方法,如果有誰(shuí)知道其他方法,敬請(qǐng)告知2012-04-04
C#中實(shí)現(xiàn)任意List的全組合算法代碼
這篇文章主要是介紹了.net C# 實(shí)現(xiàn)任意List的全組合算法實(shí)現(xiàn)代碼,需要的朋友可以參考下2013-05-05
基于WPF實(shí)現(xiàn)帶蒙版的MessageBox消息提示框
這篇文章主要介紹了如何利用WPF實(shí)現(xiàn)帶蒙版的MessageBox消息提示框,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,需要的可以參考一下2022-08-08

