JavaScript to get FCKeditor content

Source: Internet
Author: User

The format is as follows: CopyCode The Code is as follows: varoeditor = fckeditorapi. getinstance ('content ');
Varcontent = oeditor. getxhtml (true );

**************************************** *********
Using JavaScript to retrieve and set the FCKeditor value is also very easy, as shown below:Copy codeThe Code is as follows: // obtain the HTML content in the editor.
Function geteditorhtmlcontents (editorname ){
VaR oeditor = fckeditorapi. getinstance (editorname );
Return (oeditor. getxhtml (true ));
}
// Obtain the text in the editor
Function geteditortextcontents (editorname ){
VaR oeditor = fckeditorapi. getinstance (editorname );
Return (oeditor. editordocument. Body. innertext );
}
// Set the content in the editor
Function seteditorcontents (editorname, contentstr ){
VaR oeditor = fckeditorapi. getinstance (editorname );
Oeditor. sethtml (contentstr );
}

Fckeditorapi is a global object registered after FCKeditor is loaded. You can use it to complete various operations on the editor.
Get the fck editor instance on the current page:
VaR editor = fckeditorapi. getinstance ('instancename ');
Obtain the fck editor instance from the pop-up window of the fck Editor:
VaR editor = Window. Parent. innerdialogloaded (). fck;
Obtain the fck editor instance of other sub-frameworks from the sub-frameworks on the Framework page:
VaR editor = Window. framename. fckeditorapi. getinstance ('instancename ');
Obtain the fck editor instance of the parent window from the pop-up window:
VaR editor = opener. fckeditorapi. getinstance ('instancename ');
Get the fck editor content:
Oeditor. getxhtml (formatted); // formatted: True | false, indicating whether to retrieve data in HTML Format
Also available:
Oeditor. getxhtml ();
Set the content of the fck Editor:
Oeditor. sethtml ("content", false); // The second parameter is true | false. Whether to set the content in WYSIWYG mode. This method is often used in "set initial value" or "form RESET.
Insert the content to the fck Editor:
Oeditor. inserthtml ("html"); // "html" is HTML text
Check whether the content of the fck editor has changed:
Oeditor. isdirty ();
Call the fck editor toolbar Command outside the fck Editor:
The command list is as follows:
Docprops, templates, Link, unlink, anchor, random, numberedlist, about, find, replace, image, Flash, specialchar, smiley, table, tableprop, tablecellprop, universalkey, style, fontname, fontsize, fontformat, source, preview, save, Newpage, pagebreak, textcolor, bgcolor, pastetext, pasteword, delimiter, tabledeletecolumns, delimiter, tabledeletecells, delimiter, tablesplitcell, tabledelete, form, checkbox, radio, textfield, textarea, hiddenfield, button, select, imagebutton, spellcheck, fitwindow, undo, redo
The usage is as follows:
Oeditor. commands. getcommand ('fitwindow'). Execute ();
= Fckconfig. basepath + 'ins INS /'
// Fckconfig. plugins. Add ('holder', 'en, it ');

after the plug-in is removed, it is equivalent to adding the placeholder plug-in function. The plug-in files of FCKeditor are classified under/Editor/plugins/file folder and placed in folders, for fckeditor2.0, there are two folders, that is, two official plug-ins. The placeholder folder is added just now. It is mainly used for matching custom tags with multiple parameters or single parameters, this is useful when creating and editing templates. If you want to view specific instances, you can download the ACMS System for viewing and learning. Another folder tablecommands is used for editing tables in the editor. Of course, if you want to create your own plug-ins for other purposes, you just need to follow the fckeidtor plug-in creation rules and place them under/Editor/plugins/, and then in fckeidtor. add fckconfig in Js. plugins. add ('in in name', ', Lang, Lang.
In the second part, how can I keep the toolbar unchanged when the editor is opened, and wait until you click "Expand toolbar? Easy: FCKeditor provides this function to enable fckconfig. JS, find
fckconfig. toolbarstartexpanded = true;
changed to
fckconfig. toolbarstartexpanded = false;
OK!
Part 3: Use your own emoticon icon to enable fckcofnig. copy Code the code is as follows: fckconfig. smileypath = fckconfig. basepath + 'images/smiley/MSN/';
fckconfig. smileyimages = require 'regular_smile.gif', 'sad_smile.gif', 'wink_smile.gif '];
fckconfig. smileycolumns = 8;
fckconfig. smiley1_wwidth = 320;
fckconfig. smileyappswheight = 240;

I have modified the above section. The layout for posting this article will not be too open. I changed the fckconfig. smileyimages line to only three emojis.
The first line, of course, is the settings of the emoticon icon path, the second line is a list of the emoticon icon file names, and the third line is the number of emoticon added to the maximum line of the window in the pop-up window, the following two parameters are the width and height of the pop-up modal window.
Part 4: File Upload Management
This part may be of the greatest concern to everyone. Article It briefly explains how to modify the file upload and the quick upload feature provided by fckeidtor2.0. Let's continue to explain the upload function in depth.
Fckconfig. linkbrowser = true;
Fckconfig. imagebrowser = true;
Fckconfig. flashbrowser = true; In fckconfig. JS found these three sentences. These three sentences are not connected. I just concentrated them here, if this parameter is set to true, you can use FCKeditor to browse file images and Flash files on the server. This function is displayed by the "Browse server" button in the window that appears when you insert an image, if your editor is only used for your own use or only for background management, this function is undoubtedly very useful, because it allows you to upload files on the server intuitively. However, if your system is intended for front-end users or systems like blogs, this security risk will be huge. Therefore, we set all the values to false, as shown below:
Fckconfig. linkbrowser = false;
Fckconfig. imagebrowser = false;
Fckconfig. flashbrowser = false;
In this way, only quick upload is available! Next, let's modify it. It also uses ASP as an example to go to/Editor/filemanager/upload/asp/Open config. asp and modify
Configuserfilespath = "/userfiles/" is the total directory of the uploaded files. I won't move it here. You want to change it yourself.
Okay. Open the upload. asp file under this directory and find the following section. Copy code The Code is as follows: dim resourcetype
If (request. querystring ("type") <> "") then
Resourcetype = request. querystring ("type ")
Else
Resourcetype = "file"
End if

And then add

Configuserfilespath = configuserfilespath & resourcetype & "/" & year (date () & "/" & month (date ())&"/"
In this way, the uploaded file will go to the folder "/userfiles/file type (such as image, file, or flash)/year/month, this setting is enough for a single user. If you want to use it for a multi-user system, you can change it like this.

Configuserfilespath = configuserfilespath & SESSION ("username") & resourcetype & "/" & year (date () & "/" & month (date ())&"/"
In this way, the uploaded file will go to "/userfiles/user directory/file type/year/month/". Of course, if you do not want to make such an arrangement, you can change it to another one, for example, if the user directory is further layered, modify or replace the session ("username") here as needed.
The uploaded directory is set up, but the uploadProgramThese folders will not be created by ourselves. If they do not exist, the upload will not be successful, so we have to recursively generate directories according to the requirements of the upload path above.
Find this sectionCopy codeThe Code is as follows: dim sserverdir
Sserverdir = server. mappath (configuserfilespath)
If (right (sserverdir, 1) <> "\") then
Sserverdir = sserverdir &"\"
End if

Put the two rows below it

dim ofso
set ofso = server. createobject ("scripting. fileSystemObject ")
use the following code to replace copy Code the code is as follows: dim arrpath, strtmppath, introw
strtmppath =" "
arrpath = Split (sserverdir, "\")
dim ofso
set ofso = server. createobject ("scripting. fileSystemObject ")
for introw = 0 to ubound (arrpath)
strtmppath = strtmppath & arrpath (introw) &" \ "
If ofso. folderexists (strtmppath) = false then
ofso. createfolder (strtmppath)
end if
next

use this code to generate the desired folder, which is automatically generated during upload.
now, the modification to the uploaded file has come to an end. However, this problem still exists for Chinese users, that is, FCKeditor's file upload is not renamed by default, and does not support Chinese file names. In this case, uploaded files will be converted into files that cannot be read, and there will be duplicate files. Of course, there is nothing to do with duplicate names, because FCKeditor will automatically change its name, it will be marked with (1) After the file name. However, our usual habit is to allow the program to automatically generate non-repeated file names
below the code just now is
'get the uploaded file name.
sfilename = ouploader. file ("newfile "). name
it is clear that this is the file name. Let's change it. Of course, you must have a function that generates the file name. Change it to the following copy Code the code is as follows: '// obtain a non-repeated serial number
Public Function getnewid ()
dim rannum
dim dtnow
randomize
dtnow = now ()
rannum = int (90000 * RND) + 10000
getnewid = year (dtnow) & right ("0" & month (dtnow), 2) & right ("0" & Day (dtnow), 2) & right ("0" & hour (dtnow), 2) & right ("0" & minute (dtnow ), 2) & right ("0" & Second (dtnow), 2) & rannum
end function
'get the uploaded file name.
sfilename = getnewid ()&". "& Split (ouploader. file ("newfile "). name ,". ") (1)

in this example, the uploaded file is automatically renamed to generate a file name such as 20050802122536365.jpg. It is a file name consisting of a year, a month, a day, a minute, a second, and three random numbers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.