使用JAVASCRIPT版的FCK,在页面加载时(未打开FCK),创建一个隐藏的TextArea域,这个TextArea的name和ID要和创建的FCK实例名称一致,然后点击"Open Editor"按钮时,通过调用一段函数,使用FCK的ReplaceTextarea()方法来创建FCKeditor,代码如下:
java 代码
- <script type="text/javascript">
- <!--
- function showFCK(){
- var oFCKeditor = new FCKeditor( 'content' ) ;
- oFCKeditor.BasePath = '/FCKeditor/' ;
- oFCKeditor.ToolbarSet = 'Basic' ;
- oFCKeditor.Width = '100%' ;
- oFCKeditor.Height = '300' ;
- oFCKeditor.ReplaceTextarea() ;
- }
- //-->
- </script>
- <textarea name="content" id="content">textarea>
FCKeditor 的 APIOnUploadCompleted方法将上传图片的信息返回给插入图片对话框,此信息中最主要的是图片上传后的相对于网站的相对地址。如果是插入成功,应该是
java 代码
- var oEditor = FCKeditorAPI.GetInstance('FCKeditor1') ;
- // Get the Editor Area DOM (Document object)
- var oDOM = oEditor.EditorDocument ;
- iLength = oDOM.body.innerText.length ;
- // Insert the desired HTML.
- oEditor.InsertHtml( '- This is some <a href="/Test1.html">sample</a> HTML -' ) ;
- // Set the editor contents (replace the actual one).
- oEditor.SetHTML( 'This is the <b>new content</b> I want in the editor.' ) ;
- // Get the editor contents in XHTML."true" means you want it formatted.
- oEditor.GetXHTML( true ) ;
- //Get innerHtml
- oEditor.EditorDocument.body.innerHTML ;
- oEditor.IsDirty() ;
- oEditor.ResetIsDirty() ;
- // Execute the command.(Bold,Italic......)
- oEditor.Commands.GetCommand( commandName ).Execute() ;
插入及上传图片的页面fck_image,跳转到该页面的语句在/js/fckeditorcode_ie.js的75行1328列
case 'Image':B=new FCKDialogCommand('Image',FCKLang.DlgImgTitle,'dialog/fck_image.html',450,400);break;
插入flash的也在这里。
在上传图片的代码后面加入以下代码,主要是对图片上传完之后的处理,如提示信息等,可以根据需要酌情修改。
java 代码
- <script language="javascript">
- window.parent.OnUploadCompleted(returnVal, imgUrl ,fileName,errorMessage)
- </script>
java 代码
- <script language="javascript">
- window.parent.OnUploadCompleted(0, imgUrl, fileName,errorMessage );
- </script>