因為網站的需要,想要使用fckeditor對長的新聞進行分頁,在網上找了找,解決方案不明確而且又很散,於是自己動手改改
首先修改FCKeditor\editor\js\裡面的兩個js檔案,fckeditorcode_gecko.js,fckeditorcode_ie.js
1.找到<span style="DISPLAY:none"> </span>修改為:$[page]$
2.去掉e.style.pageBreakAfter = 'always';(沒有去掉的話,分頁的時候內容亂了,我也不知道去掉了對不對)
上面修改的就是fckeditor插入分頁符的內容,這樣好在分頁方法裡面替換
下面貼上分頁的方法
/// <summary> ///文章分頁函數 /// </summary> /// <param name="content">文章內容</param> /// <param name="currentPage">當前頁碼</param> /// <param name="pageUrl">當前頁面地址</param> protected void ArticlePage(string content, int currentPage, string pageUrl) { int pageCount = 0;//頁數 content = content.Replace("<div>$[page]$/div>", "[--page--]"); string[] tempContent = System.Text.RegularExpressions.Regex.Split(content, "\\u005B--page--]"); //取得分頁符 "\\u005B"為"["的轉義 pageCount = tempContent.Length; string outputContent = "";//要輸出的內容 if (pageCount <= 1) { outputContent = content; //文章內容 this.pnlPage.Visible = false; } else { string pageStr = "";//分頁字串 pageStr += "共 <span style='font-weight:bold'>" + pageCount + "</span> 頁 "; if (currentPage != 1) { pageStr += " <a class='prev' href =" + pageUrl + "&page=" + (currentPage - 1) + ">上一頁</a> "; } for (int i = 1; i <= pageCount; i++) { if (i == currentPage) pageStr += ("<span class='active'> " + i + " </span>"); else pageStr += ("<a class='num' href =" + pageUrl + "&page=" + i + "> [" + i + "] </a>"); } if (currentPage != pageCount) { pageStr += " <a class='next' href =" + pageUrl + "&page=" + (currentPage + 1) + ">下一頁</a> "; } this.lbl_page.Text = pageStr;//分頁的頁碼 outputContent = tempContent[currentPage - 1].ToString(); } this.Literal1.Text = outputContent;//顯示文章的內容 }//此分頁方法是網路上尋找整理的
這種fckeditor分頁的方式有點死板,不知道各位大蝦有木有更好的方法,指教!!!