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 | Enter鍵入代碼
FCKConfig.ShiftEnterMode = 'br' ; // p | div | br | Shift加Enter鍵入代碼
FCKConfig.Keystrokes = [
[ CTRL + 65 , true ],
[ CTRL + 67 , true ],
[ CTRL + 70 , true ],
[ CTRL + 83 , true ],
[ CTRL + 88 , true ],
[ CTRL + 86 , 'Paste' ],
[ SHIFT + 45 , 'Paste' ],
[ CTRL + 88 , 'Cut' ],
[ SHIFT + 46 , 'Cut' ],
[ CTRL + 90 , 'Undo' ],
[ CTRL + 89 , 'Redo' ],
[ CTRL + SHIFT + 90 , 'Redo' ],
[ CTRL + 76 , 'Link' ],
[ CTRL + 66 , 'Bold' ],
[ CTRL + 73 , 'Italic' ],
[ CTRL + 85 , 'Underline' ],
[ CTRL + SHIFT + 83 , 'Save' ],
[ CTRL + ALT + 13 , 'FitWindow' ],
[ CTRL + 9 , '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