欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

FCKeditorAPI 手册 js操作获取等

程序员文章站 2022-06-23 21:59:25
复制代码 代码如下:function abc() { var checkcontent =fckeditorapi.getinstance("editor");//获取实例...
复制代码 代码如下:

function abc()
{
var checkcontent =fckeditorapi.getinstance("editor");//获取实例
alert(checkcontent.getxhtml());//获取当前内容
var newelement = document.createelement("a");
newelement.href="#";
newelement.innerhtml="df";
checkcontent.insertelement(newelement);//前部添加元素(无返回值)
var a=checkcontent.insertelementandgetit(newelement);//前部添加元素(返回元素)
checkcontent.inserthtml("")//添加html
checkcontent.sethtml("",true);//设置内容,后为bool,是否所见即所得

}
function aaa()
{
var checkcontent =fckeditorapi.getinstance("editor");//获取实例
checkcontent.switcheditmode();//转变编辑模式
checkcontent.updatelinkedfield();//更新关联文件
}
function fckeditor_oncomplete( checkcontent )//当加载完
{
alert( checkcontent.name ) ;
}

//设置fckeditor为只读
function fckeditor_oncomplete(editorinstance)
{
editorinstance.editordocument.body.disabled = true;
editorinstance.editorwindow.parent.document.getelementbyid ('xexpanded').style.display = 'none';
editorinstance.editorwindow.parent.document.getelementbyid('xcollapsed').style.display = 'none';
editorinstance.editorwindow.blur();
}

//向编辑器插入指定代码
function inserthtmltoeditor(codestr){
var oeditor = fckeditorapi.getinstance("content");
if (oeditor.editmode==fck_editmode_wysiwyg){
oeditor.inserthtml(codestr);
}else{
return false;
}
}
//统计编辑器中内容的字数
function getlength(){
var oeditor = fckeditorapi.getinstance("content");
var odom = oeditor.editordocument;
var ilength ;
if(document.all){
ilength = odom.body.innertext.length;
}else{
var r = odom.createrange();
r.selectnodecontents(odom.body);
ilength = r.tostring().length;
}
alert(ilength);
}
//执行指定动作
function executecommand(commandname){
var oeditor = fckeditorapi.getinstance("content") ;
oeditor.commands.getcommand(commandname).execute() ;
}
//设置编辑器中内容
function setcontents(codestr){
var oeditor = fckeditorapi.getinstance("content") ;
oeditor.sethtml(codestr) ;
}

//使用fckeditor时使用js在光标处添加任意字符串
function inserthtml(e,instr)//e:fckeditor的id,instr:要插入的信息
{
var oeditor = fckeditorapi.getinstance(e) ;
if ( oeditor.editmode == fck_editmode_wysiwyg )
{
oeditor.inserthtml( instr ) ;
}
else
alert("you must be on wysiwyg mode!" ) ;
}

function executecommand( commandname,e )
{
var oeditor = fckeditorapi.getinstance(e) ;
oeditor.commands.getcommand(commandname ).execute() ;
}