asp.net中
FCKeditor是目前最好的html文本編輯器,如果還不明白的話看了下圖就知道了效果圖:
那麼爲什麼說是FCKeditor的冰冷之心呢?這不是譁衆取寵,主要是說它使用起來有點麻煩,下文就詳細說明如何搞定這玩意兒。
1.FCKeditor的官方網站是:http://www.fckeditor.net/download
目前最新的FCKeditor 2.4.2版本。
請在此頁下載:http://sourceforge.net/project/showfiles.php?group_id=75348
如圖所示:
要下載FCKeditor2.4.2.zip和 FCKeditor.NET版的2個zip包。
說明:
FCKeditor2.4.2.zip是其最新的Javascript文件和圖片什麼的;
FCKeditor.NET.zip是ASP.NET調用的DLL在裏面。
2.分別解壓後把FCKeditor2.4.2.zip裏的fckeditor目錄整個複製到網站中。
3.解壓FCKeditor.NET.zip包後在FCKeditor.Net_2.2/bin/Debug目錄裏找到FredCK.FCKeditorV2.dll。其他文件沒用,把FredCK.FCKeditorV2.dll複製到我們的網站,建立一個Bin目錄。
4.引用FredCK.FCKeditorV2.dll。
第一步:
第二步:
5.導入工具箱。
在“工具箱”下右鍵
點擊“選擇項”。彈出如圖窗口:
點擊瀏覽,找到dll所在目錄。
這時發現工具箱裏多出FCKeditor控件。
6.拖拽FCKeditor到頁面上
7.配置WebConfig
<?xml version="1.0"?>
<!--
注意: 除了手動編輯此文件以外,您還可以使用
Web 管理工具來配置應用程序的設置。可以使用 Visual Studio 中的
“網站”->“Asp.Net 配置”選項。
設置和註釋的完整列表在
machine.config.comments 中,該文件通常位於
/Windows/Microsoft.Net/Framework/v2.x/Config 中
-->
<configuration>
<appSettings>
<add key="FCKeditor:BasePath" value="~/fckeditor/"/>
<add key="FCKeditor:UserFilesPath" value="/Files/" />
</appSettings>
<connectionStrings/>
<system.web>
說明:BasePath是fckeditor所在路徑,fckeditor由於我們直接放網站目錄下這樣寫就可以,如果您的網站多放幾層適當調整即可。
UserFilesPath是所有上傳的文件的所在目錄。爲什麼要設置成/Files這樣而不是~/Files,因爲FCKeditor使用這個值來返回你上傳後的文件的相對路徑到客戶端。否則的話客戶訪問的時候就會取客戶的機器目錄而不是http形式的目錄。
建議:Files要單獨做wwwroot目錄下的一個站點比較好,和我們的站點FCKEditor平行。不要把它放FCKEditor裏,爲什麼呢?因爲Files是要讓客戶有寫的權限的,如果放FCKEditor下很危險。
8.Files目錄要有寫的權限。你根據自己網站需求設置那個帳號,本文爲方便設置User實際中你可能用ASP.NET帳號更合理。
9.修改fckeditor/fckconfig.js文件
在第182行的位置
var _FileBrowserLanguage = 'asp' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'asp' ; // asp | aspx | cfm | lasso | php
改爲
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | php
10.FCKeditor給其瘦身。以_打頭的的都是範例文件或源文件,不過建議小心。
11.下面以上傳圖片示例說明如何使用,
點擊“瀏覽服務器”。
彈出窗口很容易報錯
如果報錯XML request error: Internal Server Error(500),很可能就是目錄路徑不對和寫權限沒有。
選擇圖像
最後效果
前臺代碼:
<%@ Page Language="C#" validateRequest=false AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>FCKeditor文本編輯器</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<fckeditorv2:fckeditor id="FCKeditor1" runat="server" DefaultLanguage="zh-cn" Height="400px" Width="660px"
></fckeditorv2:fckeditor>
</div>
</form>
</body>
</html>
怎麼樣獲取結果呢?FCKeditor1.Value就是。
web.config中配置
<location>
<appSettings>
<add key="FCKeditor:BasePath" value="~/FCKeditor/" />
<add key="FCKeditor:UserFilesPath" value="~/FCK_upload/" />
</appSettings>
</location>
<location path="fckeditor">
<system.web>
<pages theme="">
</pages>
</system.web>
</location>
fckconfig.js中配置
FCKConfig.DefaultLanguage = 'zh-cn' ;
FCKConfig.FontNames = '宋體;黑體;隸書;楷體_GB2312;華文行楷;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;//設置字體列表
var _FileBrowserLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = 'aspx' ; // asp | aspx | cfm | lasso | perl | php | py
=======================================================================
asp中配置方法
1.修改文件 /Fckeditor/editor/filemanager/connectors/asp/io.asp
Sub SendUploadResults( errorNumber, fileUrl, fileName, customMsg )
Response.Clear
Response.CodePage=65001'新增加的行,防止中文亂碼
Response.Charset="UTF-8"'新增加的行,防止中文亂碼
Response.Write "<script type=""text/javascript"">"
Response.Write "window.parent.OnUploadCompleted(" & errorNumber & ",""" & Replace( fileUrl, """", "/""" ) & """,""" & Replace( fileName, """", "/""" ) & """,""" & Replace( customMsg , """", "/""" ) & """) ;"
Response.Write "</script>"
Response.End
End Sub
2.修改文件 /Fckeditor/editor/filemanager/connectors/asp/config.asp
ConfigIsEnabled = True '設置允許上傳
ConfigUserFilesPath = "/Upload/FCK/" '設置用戶上傳文件
ConfigAllowedExtensions.Add "File", "asf|bmp|doc|fla|flv|gif|jpeg|jpg|mid|mp3|pdf|png|ppt|rm|rmi|rtf|swf|txt|wma|wmv|xls|xml"
ConfigDeniedExtensions.Add "File", "asp|aspx|asa|asax|java|class|exe|php|pl|dll"
ConfigAllowedExtensions.Add "Image", "bmp|gif|jpeg|jpg|png"
ConfigAllowedExtensions.Add "Media", "asf|bmp|fla|flv|gif|jpeg|jpg|mid|mp3|png|ram|rm|rmi|swf|wma|wmv"
3.編輯區域的主CSS文件是 /Fckeditor/editor/css/fck_editorarea.css
4.整個fckconfig.js
FCKConfig.CustomConfigurationsPath = '' ;//自定義配置文件路徑和名稱
FCKConfig.EditorAreaCSS = FCKConfig.BasePath + 'css/fck_editorarea.css' ;
FCKConfig.EditorAreaStyles = '' ;//編輯區的樣式表文件
FCKConfig.ToolbarComboPreviewCSS = '' ;
FCKConfig.DocType = '' ;
FCKConfig.BaseHref = '' ;//相對鏈接的基地址
FCKConfig.FullPage = false ;//是否允許編輯整個HTML文件,還是僅允許編輯BODY間的內容
// The following option determines whether the "Show Blocks" feature is enabled or not at startup.
FCKConfig.StartupShowBlocks = false ;
FCKConfig.Debug = false ;
FCKConfig.AllowQueryStringDebug = true ;
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/' ;//編輯器皮膚 default silver office2003
FCKConfig.PreloadImages = [ FCKConfig.SkinPath + 'images/toolbar.start.gif', FCKConfig.SkinPath + 'images/toolbar.buttonarrow.gif' ] ;
FCKConfig.PluginsPath = FCKConfig.BasePath + 'plugins/' ;
// FCKConfig.Plugins.Add( 'autogrow' ) ;
// FCKConfig.Plugins.Add( 'dragresizetable' );
FCKConfig.AutoGrowMax = 400 ;
// FCKConfig.ProtectedSource.Add( /<%[/s/S]*?%>/g ) ; // ASP style server side code <%...%>
// FCKConfig.ProtectedSource.Add( /</?[/s/S]*?/?>/g ) ; // PHP style server side code
// FCKConfig.ProtectedSource.Add( /(<asp:[^/>]+>[/s|/S]*?<//asp:[^/>]+>)|(<asp:[^/>]+//>)/gi ) ; // ASP.Net style tags <asp:control>
FCKConfig.AutoDetectLanguage = true ;//自動檢測語言
FCKConfig.DefaultLanguage = 'zh-cn' ;//設置語言
FCKConfig.ContentLangDirection = 'ltr' ;//默認文字方向
FCKConfig.ProcessHTMLEntities = true ;
FCKConfig.IncludeLatinEntities = true ;
FCKConfig.IncludeGreekEntities = true ;
FCKConfig.ProcessNumericEntities = false ;
FCKConfig.AdditionalNumericEntities = '' ; // Single Quote: "'"
FCKConfig.FillEmptyBlocks = true ;//使用這個功能,可以將空的塊級元素用空格來替代
FCKConfig.FormatSource = true ;//在切換到代碼視圖時是否自動格式化代碼
FCKConfig.FormatOutput = true ;
FCKConfig.FormatIndentator = ' ' ;
FCKConfig.StartupFocus = false ;//開啓時FOCUS到編輯器
FCKConfig.ForcePasteAsPlainText = false ;//強制粘貼爲純文本
FCKConfig.AutoDetectPasteFromWord = true ; // IE only.
FCKConfig.ShowDropDialog = true ;
FCKConfig.ForceSimpleAmpersand = false ;//是否不把&符號轉換爲XML實體
FCKConfig.TabSpaces = 1 ;//在編輯器中是否可以是否TAB鍵 0 不可用 1 爲可用
FCKConfig.ShowBorders = true ;//合併邊框
FCKConfig.SourcePopup = false ;
FCKConfig.ToolbarStartExpanded = true ;
FCKConfig.ToolbarCanCollapse = true ;//是否允許展開/摺疊工具欄
FCKConfig.IgnoreEmptyParagraphValue = true ;
FCKConfig.PreserveSessionOnFileBrowser = false ;
FCKConfig.FloatingPanelsZIndex = 10000 ;
FCKConfig.HtmlEncodeOutput = false ;
FCKConfig.TemplateReplaceAll = true ;
FCKConfig.TemplateReplaceCheckbox = true ;
FCKConfig.ToolbarLocation = 'In' ;
FCKConfig.ToolbarSets["Default"] = [
['Source','DocProps','-','Save','NewPage','Preview','-','Templates'],
['Cut','Copy','Paste','PasteText','PasteWord','-','Print','SpellCheck'],
['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField'],
'/',
['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
['Link','Unlink','Anchor'],
['Image','Flash','Table','Rule','Smiley','SpecialChar','PageBreak'],
'/',
['Style','FontFormat','FontName','FontSize'],
['TextColor','BGColor'],
['FitWindow','ShowBlocks']// No comma for the last row.
] ;
FCKConfig.ToolbarSets["Redgull"] = [
['Source','-','Preview','ShowBlocks','FitWindow','-','Templates'],
['Cut','Copy','Paste','PasteText','PasteWord','Undo','Redo'],
['Find','Replace','-','SelectAll','RemoveFormat'],'/',
['TextColor','BGColor','-','Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
['OrderedList','UnorderedList','-','Outdent','Indent','-','JustifyLeft','JustifyCenter','JustifyRight','Link','Unlink'],'/',
['Style','FontFormat','FontName','FontSize'],'/',
['Form','Checkbox','Radio','TextField','Textarea','Select','Button','ImageButton','HiddenField','-','Image','Flash','Table','Rule','Smiley','SpecialChar']
] ;
FCKConfig.ToolbarSets["Basic"] = [['Bold','Italic','-','OrderedList','UnorderedList','-','Link','Unlink']];
FCKConfig.EnterMode = 'p' ; // p | div | br | 回車鍵入代碼
FCKConfig.ShiftEnterMode = 'br' ; // p | div | br | Shift加回車鍵入代碼
FCKConfig.Keystrokes = [
[ CTRL + 65 /*A*/, true ],
[ CTRL + 67 /*C*/, true ],
[ CTRL + 70 /*F*/, true ],
[ CTRL + 83 /*S*/, true ],
[ CTRL + 88 /*X*/, true ],
[ CTRL + 86 /*V*/, 'Paste' ],
[ SHIFT + 45 /*INS*/, 'Paste' ],
[ CTRL + 88 /*X*/, 'Cut' ],
[ SHIFT + 46 /*DEL*/, 'Cut' ],
[ CTRL + 90 /*Z*/, 'Undo' ],
[ CTRL + 89 /*Y*/, 'Redo' ],
[ CTRL + SHIFT + 90 /*Z*/, 'Redo' ],
[ CTRL + 76 /*L*/, 'Link' ],
[ CTRL + 66 /*B*/, 'Bold' ],
[ CTRL + 73 /*I*/, 'Italic' ],
[ CTRL + 85 /*U*/, 'Underline' ],
[ CTRL + SHIFT + 83 /*S*/, 'Save' ],
[ CTRL + ALT + 13 /*ENTER*/, 'FitWindow' ],
[ CTRL + 9 /*TAB*/, 'Source' ]
] ;
//右鍵菜單的內容
FCKConfig.ContextMenu = ['Generic','Link','Anchor','Image','Flash','Select','Textarea','Checkbox','Radio','TextField','HiddenField','ImageButton','Button','BulletedList','NumberedList','Table','Form'] ;
FCKConfig.BrowserContextMenuOnCtrl = false ;
FCKConfig.EnableMoreFontColors = true ;
FCKConfig.FontColors = '000000,993300,333300,003300,003366,000080,333399,333333,800000,FF6600,808000,808080,008080,0000FF,666699,808080,FF0000,FF9900,99CC00,339966,33CCCC,3366FF,800080,999999,FF00FF,FFCC00,FFFF00,00FF00,00FFFF,00CCFF,993366,C0C0C0,FF99CC,FFCC99,FFFF99,CCFFCC,CCFFFF,99CCFF,CC99FF,FFFFFF' ;
FCKConfig.FontFormats = 'p;h1;h2;h3;h4;h5;h6;pre;address;div' ;
FCKConfig.FontNames = '宋體;黑體;隸書;楷體_GB2312;華文行楷;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;//設置字體列表
FCKConfig.FontSizes = '12px;14px;smaller;larger;xx-small;x-small;small;medium;large;x-large;xx-large' ;
FCKConfig.StylesXmlPath = FCKConfig.EditorPath + 'fckstyles.xml' ;
FCKConfig.TemplatesXmlPath = FCKConfig.EditorPath + 'fcktemplates.xml' ;
FCKConfig.SpellChecker = 'ieSpell' ; // 'ieSpell' | 'SpellerPages'
FCKConfig.IeSpellDownloadUrl = 'http://www.iespell.com/download.php' ;
FCKConfig.SpellerPagesServerScript = 'server-scripts/spellchecker.php' ; // Available extension: .php .cfm .pl
FCKConfig.FirefoxSpellChecker = false ;
FCKConfig.MaxUndoLevels = 15 ;
FCKConfig.DisableObjectResizing = false ;
FCKConfig.DisableFFTableHandles = true ;
FCKConfig.LinkDlgHideTarget = false ;
FCKConfig.LinkDlgHideAdvanced = false ;
FCKConfig.ImageDlgHideLink = false ;
FCKConfig.ImageDlgHideAdvanced = false ;
FCKConfig.FlashDlgHideAdvanced = false ;
FCKConfig.ProtectedTags = '' ;
// This will be applied to the body element of the editor
FCKConfig.BodyId = '' ;
FCKConfig.BodyClass = '' ;
FCKConfig.DefaultStyleLabel = '' ;
FCKConfig.DefaultFontFormatLabel = '' ;
FCKConfig.DefaultFontLabel = '' ;
FCKConfig.DefaultFontSizeLabel = '' ;
FCKConfig.DefaultLinkTarget = '' ;
// The option switches between trying to keep the html structure or do the changes so the content looks like it was in Word
FCKConfig.CleanWordKeepsStructure = false ;
// Only inline elements are valid.
FCKConfig.RemoveFormatTags = 'b,big,code,del,dfn,em,font,i,ins,kbd,q,samp,small,span,strike,strong,sub,sup,tt,u,var' ;
FCKConfig.CustomStyles =
{
'Red Title' : { Element : 'h3', Styles : { 'color' : 'Red' } }
};
// Do not add, rename or remove styles here. Only apply definition changes.
FCKConfig.CoreStyles =
{
// Basic Inline Styles.
'Bold' : { Element : 'b', Overrides : 'strong' },
'Italic' : { Element : 'i', Overrides : 'em' },
'Underline' : { Element : 'u' },
'StrikeThrough' : { Element : 'strike' },
'Subscript' : { Element : 'sub' },
'Superscript' : { Element : 'sup' },
// Basic Block Styles (Font Format Combo).
'p' : { Element : 'p' },
'div' : { Element : 'div' },
'pre' : { Element : 'pre' },
'address' : { Element : 'address' },
'h1' : { Element : 'h1' },
'h2' : { Element : 'h2' },
'h3' : { Element : 'h3' },
'h4' : { Element : 'h4' },
'h5' : { Element : 'h5' },
'h6' : { Element : 'h6' },
// Other formatting features.
'FontFace' :
{
Element : 'span',
Styles : { 'font-family' : '#("Font")' },
Overrides : [ { Element : 'font', Attributes : { 'face' : null } } ]
},
'Size' :
{
Element : 'span',
Styles : { 'font-size' : '#("Size","fontSize")' },
Overrides : [ { Element : 'font', Attributes : { 'size' : null } } ]
},
'Color' :
{
Element : 'span',
Styles : { 'color' : '#("Color","color")' },
Overrides : [ { Element : 'font', Attributes : { 'color' : null } } ]
},
'BackColor' : { Element : 'span', Styles : { 'background-color' : '#("Color","color")' } }
};
// The distance of an indentation step.
FCKConfig.IndentLength = 40 ;
FCKConfig.IndentUnit = 'px' ;
// Alternatively, FCKeditor allows the use of CSS classes for block indentation.
// This overrides the IndentLength/IndentUnit settings.
FCKConfig.IndentClasses = [] ;
// [ Left, Center, Right, Justified ]
FCKConfig.JustifyClasses = [] ;
// The following value defines which File Browser connector and Quick Upload
// "uploader" to use. It is valid for the default implementaion and it is here
// just to make this configuration file cleaner.
// It is not possible to change this value using an external file or even
// inline when creating the editor instance. In that cases you must set the
// values of LinkBrowserURL, ImageBrowserURL and so on.
// Custom implementations should just ignore it.
var _FileBrowserLanguage = 'asp' ; // asp | aspx | cfm | lasso | perl | php | py | 使用什麼寫什麼
var _QuickUploadLanguage = 'asp' ; // asp | aspx | cfm | lasso | perl | php | py | 使用什麼寫什麼
// Don't care about the following two lines. It just calculates the correct connector
// extension to use for the default File Browser (Perl uses "cgi").
var _FileBrowserExtension = _FileBrowserLanguage == 'perl' ? 'cgi' : _FileBrowserLanguage ;
var _QuickUploadExtension = _QuickUploadLanguage == 'perl' ? 'cgi' : _QuickUploadLanguage ;
FCKConfig.LinkBrowser = false ;//是否允許在插入鏈接時瀏覽服務器
//插入鏈接時瀏覽服務器的URL
FCKConfig.LinkBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Connector=../../connectors/' + _FileBrowserLanguage + '/connector.' + _FileBrowserExtension ;
FCKConfig.LinkBrowserWindowWidth = FCKConfig.ScreenWidth * 0.7 ; // 70% 鏈接目標瀏覽器窗口寬度
FCKConfig.LinkBrowserWindowHeight = FCKConfig.ScreenHeight * 0.7 ; // 70% 鏈接目標瀏覽器窗口高度
FCKConfig.ImageBrowser = true ;//是否允許瀏覽服務器功能
//瀏覽服務器時運行的URL
FCKConfig.ImageBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Type=Image&Connector=../../connectors/' + _FileBrowserLanguage + '/connector.' + _FileBrowserExtension ;
FCKConfig.ImageBrowserWindowWidth = FCKConfig.ScreenWidth * 0.7 ; // 70% 圖像瀏覽器窗口寬度;
FCKConfig.ImageBrowserWindowHeight = FCKConfig.ScreenHeight * 0.7 ; // 70% 圖像瀏覽器窗口高度;
FCKConfig.FlashBrowser = true ;
FCKConfig.FlashBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Type=Flash&Connector=../../connectors/' + _FileBrowserLanguage + '/connector.' + _FileBrowserExtension ;
FCKConfig.FlashBrowserWindowWidth = FCKConfig.ScreenWidth * 0.7 ; //70% ;
FCKConfig.FlashBrowserWindowHeight = FCKConfig.ScreenHeight * 0.7 ; //70% ;
FCKConfig.LinkUpload = true ;
FCKConfig.LinkUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension ;
//允許上傳文件的擴展名
FCKConfig.LinkUploadAllowedExtensions = ".(asf|bmp|doc|fla|flv|gif|jpeg|jpg|mid|mp3|png|ppt|ram|rtf|swf|txt|wma|wmv)$" ;// empty for all
//禁止上傳的文件擴展名
FCKConfig.LinkUploadDeniedExtensions = "" ; // empty for no one
FCKConfig.ImageUpload = true ;
FCKConfig.ImageUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension + '?Type=Image' ;
FCKConfig.ImageUploadAllowedExtensions = ".(jpg|gif|jpeg|png|bmp)$" ; // empty for all
FCKConfig.ImageUploadDeniedExtensions = "" ; // empty for no one
FCKConfig.FlashUpload = true ;
FCKConfig.FlashUploadURL = FCKConfig.BasePath + 'filemanager/connectors/' + _QuickUploadLanguage + '/upload.' + _QuickUploadExtension + '?Type=Flash' ;
FCKConfig.FlashUploadAllowedExtensions = ".(swf|flv)$" ; // empty for all
FCKConfig.FlashUploadDeniedExtensions = "" ; // empty for no one
FCKConfig.SmileyPath = FCKConfig.BasePath + 'images/smiley/msn/' ;
FCKConfig.SmileyImages = ['regular_smile.gif','sad_smile.gif','wink_smile.gif','teeth_smile.gif','confused_smile.gif','tounge_smile.gif','embaressed_smile.gif','omg_smile.gif','whatchutalkingabout_smile.gif','angry_smile.gif','angel_smile.gif','shades_smile.gif','devil_smile.gif','cry_smile.gif','lightbulb.gif','thumbs_down.gif','thumbs_up.gif','heart.gif','broken_heart.gif','kiss.gif','envelope.gif'] ;
FCKConfig.SmileyColumns = 8 ;
FCKConfig.SmileyWindowWidth = 320 ;
FCKConfig.SmileyWindowHeight = 240 ;
對FckEditor編輯器在MAXTHON瀏覽器下選擇服務器文件對話框顯示不正常的改進
用過FckEditor的朋友都知道,它的選擇圖片對話框中“瀏覽服務器”按鈕。點擊該按鈕可以瀏覽以前已經上傳過的文件。不過這個按鈕點擊後彈出的對話框在MAXTHON瀏覽器下是以標籤形式打開的,這樣模態對話框就始終顯示在了瀏覽文件窗口之前,要想選擇文件得先關掉模態對話框。先前有朋友提出把彈出模態對話框的功能改爲ShowModlessDialog,這個終究不是解決之道,現將我的解決方法寫下來與大家分享:
思路就是基於IE內核的瀏覽器採用模態對話框彈出瀏覽服務器窗口,其他的仍然window.open不變
1:修改/fckeditor/editor/dialog/common/fck_dialog_common.js
1 function OpenFileBrowser( url, width, height )
2 {
3 // oEditor must be defined.
4
5 var iLeft = ( oEditor.FCKConfig.ScreenWidth - width ) / 2 ;
6 var iTop = ( oEditor.FCKConfig.ScreenHeight - height ) / 2 ;
7
8 var sOptions = "toolbar=no,status=no,resizable=no,dependent=yes,scrollbars=yes" ;
9 sOptions += ",width=" + width ;
10 sOptions += ",height=" + height ;
11 sOptions += ",left=" + iLeft ;
12 sOptions += ",top=" + iTop ;
13
14 // The "PreserveSessionOnFileBrowser" because the above code could be
15 // blocked by popup blockers.
16 if ( oEditor.FCKConfig.PreserveSessionOnFileBrowser && oEditor.FCKBrowserInfo.IsIE )
17 {
18 // The following change has been made otherwise IE will open the file
19 // browser on a different server session (on some cases):
20 // http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
21 // by Simone Chiaretta.
22 var oWindow = oEditor.window.open( url, 'FCKBrowseWindow', sOptions ) ;
23
24 if ( oWindow )
25 {
26 // Detect Yahoo popup blocker.
27 try
28 {
29 var sTest = oWindow.name ; // Yahoo returns "something", but we can't access it, so detect that and avoid strange errors for the user.
30 oWindow.opener = window ;
31 }
32 catch(e)
33 {
34 alert( oEditor.FCKLang.BrowseServerBlocked ) ;
35 }
36 }
37 else
38 alert( oEditor.FCKLang.BrowseServerBlocked ) ;
39 }
40 else
41 {
//這裏是修改部分
42 if(oEditor.FCKBrowserInfo.IsIE)
43 {
44 window.showModalDialog(url+"&rdm="+new Date(),window,"status:false;dialogWidth:"+width+"px;dialogHeight:"+height+"px/"");
45 }
46 else
47 {
48 window.open( url, 'FCKBrowseWindow', sOptions ) ;
49 }
50 }
51 }
2:修改/fckeditor/editor/filemanager/browser/default/frmresourceslist.html
function OpenFile( fileUrl )
{
if( window.dialogArguments)
{
window.dialogArguments.SetUrl( fileUrl ) ;
window.close() ;
window.dialogArguments.focus() ;
}
else
{
window.top.opener.SetUrl( fileUrl ) ;
window.top.close() ;
window.top.opener.focus() ;
}
}
========================================================================
上傳附件出錯的修改方法
I had this problem as well. The problem is that it can't find the type of resource for upload. I assume that it should detect the resource type by file extension, but there is no code to do that.
I fixed it by adding the resource type "File" in the config. I think this is a workaround, but it worked for me.
So the link browser url looks somewhat like this (added Type=File&):
FCKConfig.LinkBrowserURL = FCKConfig.BasePath + 'filemanager/browser/default/browser.html?Type=File&Connector=../../../../connector.' + _FileBrowserExtension;
And the quick upload looks like this (added + '?Type=File' ):
FCKConfig.LinkUploadURL = FCKConfig.BasePath + '../upload.' + _QuickUploadExtension + '?Type=File' ;
========================================================================
asp.net 修改爲自動重命名
while ( true )
{
//string sFilePath = System.IO.Path.Combine( sServerDir, sFileName );
//if ( System.IO.File.Exists( sFilePath ) )
//{
// iCounter++;
// sFileName =
// System.IO.Path.GetFileNameWithoutExtension( oFile.FileName ) +
// "(" + iCounter + ")." +
// sExtension;
// iErrorNumber = 201;
//}
//else
//{
// oFile.SaveAs( sFilePath );
// break;
//}
//實現上傳重命名
sFileName = DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + System.IO.Path.GetExtension(oFile.FileName);
string sFilePath = System.IO.Path.Combine(sServerDir, sFileName);
oFile.SaveAs(sFilePath);
break;
}
=======================================================================
這裏介紹一個FCK的插件,多媒體插件,支持Windows Media,Real,QuickTime,Flash,Shockwave,完全可以替換FCK自帶的flash插入功能。
插件的具體使用方法如下:
1、解壓文件到 FCKeditor/editor/plugins
2、修改配置文件 FCKeditor/fckconfig.js ,包括啓用插件和添加按鈕。
JavaScript代碼
FCKConfig.PluginsPath = FCKConfig.BasePath + 'plugins/' ; //找到這一句,配置插件路徑
FCKConfig.Plugins.Add( 'Media', 'en,zh,zh-cn' ) ; //啓用插件
………… //中間代碼省略
FCKConfig.ToolbarSets["Default"] = [
['Source','Templates'],
['FontName','FontSize'],
['TextColor','BGColor'],
['Image','Flash'], //可以用Media替換Flash
['Table','Rule'],
['FitWindow','ShowBlocks'],
['Smiley','SpecialChar','Media'], //或者加入Media按鈕
'/',
['PasteText','PasteWord','RemoveFormat'],
['Undo','Redo','Find','Replace'],
['Bold','Italic','Underline','StrikeThrough'],
['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote'],
['JustifyLeft','JustifyCenter','JustifyRight'],
['Anchor','Link','Unlink'] //我的按鈕的配置,可能和你的不太一樣
] ;
找到類似代碼添加如下內容
FCKConfig.MediaUpload = true ;
FCKConfig.MediaUploadURL = FCKConfig.BasePath + 'filemanager/upload/' + _QuickUploadLanguage + '/upload.' + _QuickUploadLanguage + '?Type=Image' ;
FCKConfig.MediaUploadAllowedExtensions = ".(avi|asf)$" ; // empty for all
FCKConfig.MediaUploadDeniedExtensions = "" ; // empty for no one