在window.onload中调用也不成么?
看到楼主在fckeditor上花了N多分了,都有点不敢用了,呵呵

解决方案 »

  1.   

    我猜测噢
    可能是放的位置的问题。把 InitializeAPI() ; 放到页面最下面试试
      

  2.   


    <html>
    ....
    <body>
    ....
    <!--把调用放到这里试试-->
    </body>
    </html>
      

  3.   

    放在onload中不行啊!而且我ff2和ie都可以,就是ff3不行!并且我加上alert就可以了,我不知道有什么东西能模仿alert但是却有不打印东西出来的办法吗?
    我在这句上面写了一个延时什么的都不行!555taobao baidu都用fck的啊!可能是我js水平太差了啊。唉
      

  4.   

    页面中有几个帧?
    从现象上看象是画面没有加载完成。
    是不是父画面的东西比较多呀。
    调用其它窗口的时候判断一下 readyState == "complete";另外,失败的时候,
    楼主至少应该定位到失败的语句。在代码中加入几条alert();
    很容易就定位到出错的语句了。
    然后再找问题就容易了。
      

  5.   

    先用setTimeOut加个延迟试试,我做AJAX也碰到过类似情况,alert下就可以,其实不是加载的问题
      

  6.   

    在代码中加入几条alert(); 
    很容易就定位到出错的语句了。
      

  7.   

    看你描述的表象用window.onload可以解决的啊你看看你页面有多少帧,
    看看是不是其中的哪一个没有加载完造成的
      

  8.   

    这个方法就是在window.onload里面的
      

  9.   

    我能定位啊
          ;
          FCKeditorAPI = A.FCKeditorAPI;
          FCKeditorAPI.__Instances = FCKeditorAPI.Instances;就是FCKeditorAPI is undefined
    啊!但不知道怎么解决啊
      

  10.   

    window.onload=function(){InitializeAPI();}
    这样不可以?
      

  11.   


    没怎么用过FCK也不大了解,如果楼上的方法还是不行,这样子再试试:
    (function () { 
    if(A.FCKeditorAPI)InitializeAPI();
    else setTimeout(arguments.callee, 1000);
    })();
      

  12.   

    友情up..
     在alert之前和之后   alert那个方法看看
    反正先调试看看 alert之前和之后有哪些地方不一样
      

  13.   

    不知道你什么版本
    在fckeditor.html这个文件加中就有调用这个方法的window.onload = function()
    {
    InitializeAPI() ; if ( FCKBrowserInfo.IsIE )
    FCK_PreloadImages() ;
    else
    LoadToolbarSetup() ;
    }看到没,就是跟我说得那调用方法是一样的
      

  14.   

    比较笨的方法
    (function(){
    if(InitializeAPI)
    InitializeAPI();
    else
    setTimeout(arguments.callee, 50)
    })()
      

  15.   

    比较笨的方法
    (function(){
    if(InitializeAPI)
    InitializeAPI();
    else
    setTimeout(arguments.callee, 50)
    })()
      

  16.   

    需要同步加载,等加载完毕后才能进行其他操作var scriptObj = C.documentElement.appendChild(D);
    scriptObj.onreadystatechange = function(){
    var state = scriptObj.readyState;
    if (state == "loaded" || state == "complete") {
    // 加载完毕
    }
    };或者将InitializeAPI放在body之后试试<html>
    ...
    <body>
    ...
    </body>
    <script>
      InitializeAPI(); 
    </script>
    </html>
      

  17.   

    (function(){
        if(InitializeAPI)
            InitializeAPI();
        else
            setTimeout(arguments.callee, 50)
    })()
      

  18.   


    最感谢就是你了!帮助了我很多啊!
    可是这样解决不了fck把这段代码var B = 'window.FCKeditorAPI = {Version : "2.6.2",VersionBuild : "19417",Instances : new Object(),GetInstance : function( name ){return this.Instances[ name ];},_FormSubmit : function(){for ( var name in FCKeditorAPI.Instances ){var oEditor = FCKeditorAPI.Instances[ name ] ;if ( oEditor.GetParentForm && oEditor.GetParentForm() == this )oEditor.UpdateLinkedField() ;}this._FCKOriginalSubmit() ;},_FunctionQueue    : {Functions : new Array(),IsRunning : false,Add : function( f ){this.Functions.push( f );if ( !this.IsRunning )this.StartNext();},StartNext : function(){var aQueue = this.Functions ;if ( aQueue.length > 0 ){this.IsRunning = true;aQueue[0].call();}else this.IsRunning = false;},Remove : function( f ){var aQueue = this.Functions;var i = 0, fFunc;while( (fFunc = aQueue[ i ]) ){if ( fFunc == f )aQueue.splice( i,1 );i++ ;}this.StartNext();}}}';
         
    先当成一个变量!然后当一个js输出在在页面上!然后在用里面的方法!
    我曾经尝试把这段代码放到一个js里面然后直接在页面上引用这个js还是失败!
    而且就只有ff2.xxx17以上版本有问题!ie和以下版本都没问题!我也只是感觉是加载的问题不知道实际是是什么!
    我现在唯一的思路就是想知道有什么功能可以跟alert效果一样但是!不弹出窗口
      

  19.   


    我就是在 InitializeAPI() ; 前面alert就可以初始化,fck编辑区也显示正常
    如果去掉alert就会提示FCKeditorAPI is undefined,fck编辑区就就显示不出来然后下面就是InitializeAPI() 的全部内容啊!
    function InitializeAPI()
    {
       var A = window.parent;
       if ( ! (FCKeditorAPI = A.FCKeditorAPI))
       {
          var B = 'window.FCKeditorAPI = {Version : "2.6.2",VersionBuild : "19417",Instances : new Object(),GetInstance : function( name ){return this.Instances[ name ];},_FormSubmit : function(){for ( var name in FCKeditorAPI.Instances ){var oEditor = FCKeditorAPI.Instances[ name ] ;if ( oEditor.GetParentForm && oEditor.GetParentForm() == this )oEditor.UpdateLinkedField() ;}this._FCKOriginalSubmit() ;},_FunctionQueue    : {Functions : new Array(),IsRunning : false,Add : function( f ){this.Functions.push( f );if ( !this.IsRunning )this.StartNext();},StartNext : function(){var aQueue = this.Functions ;if ( aQueue.length > 0 ){this.IsRunning = true;aQueue[0].call();}else this.IsRunning = false;},Remove : function( f ){var aQueue = this.Functions;var i = 0, fFunc;while( (fFunc = aQueue[ i ]) ){if ( fFunc == f )aQueue.splice( i,1 );i++ ;}this.StartNext();}}}';
          if (A.execScript) A.execScript(B, 'JavaScript');
          else
          {
             if (FCKBrowserInfo.IsGecko10)
             {
                eval.call(A, B);
             }
             else if(FCKBrowserInfo.IsAIR)
             {
                FCKAdobeAIR.FCKeditorAPI_Evaluate(A, B);
             }
             else if (FCKBrowserInfo.IsSafari || FCKBrowserInfo.IsGecko19)
             {
                var C = A.document;
                var D = C.createElement('script');
                D.appendChild(C.createTextNode(B));
                C.documentElement.appendChild(D);
                
             }
             else A.eval(B);
          }
          ;
          FCKeditorAPI = A.FCKeditorAPI;
          FCKeditorAPI.__Instances = FCKeditorAPI.Instances;
       }
       ;
       FCKeditorAPI.Instances[FCK.Name] = FCK;
    }
      

  20.   


    这样判断肯定不行了,你不是InitializeAPI undefined,而是FCKeditorAPI,如果要用这种方法应该是
    (function () { 
        if(A.FCKeditorAPI)InitializeAPI();
        else setTimeout(arguments.callee, 1000);
    })();
      

  21.   


    就是这样测试的啊!下面这样也测试过不行!哎
    while(true)
    {
         if(A.FCKeditorAPI)
         {
               break;
         }
    }
      

  22.   

    while(true) 

        if(A.FCKeditorAPI) 
        { 
              break; 
        } 

    这样当然不行,死在一个循环里了,又不是两个线程,楼主的这个东西我不清楚,但可以考虑这样的方法试一下:
    var oTid = null; 
    function vid()
    {
        if(!A.FCKeditorAPI)
          return;
        clearInterval(oTid);
        you_init();
    }
    oTid setInterval(vid,1000);
      

  23.   

    while(true) 

        if(A.FCKeditorAPI) 
        { 
              break; 
        } 

    这样当然不行,死在一个循环里了,又不是两个线程,楼主的这个东西我不清楚,但可以考虑这样的方法试一下:
    var oTid = null; 
    function vid()
    {
        if(!A.FCKeditorAPI)
          return;
        clearInterval(oTid);
        you_init();
    }
    oTid = setInterval(vid,1000);
      

  24.   

    改一下你的InitializeAPI
    function InitializeAPI()
    {
       var A = window.parent;
    if(!A.FCKeditorAPI){
    return window.setTimeout(function(){InitializeAPI();},100);
    }
       if ( ! (FCKeditorAPI = A.FCKeditorAPI))
       {
          var B = 'window.FCKeditorAPI = {Version : "2.6.2",VersionBuild : "19417",Instances : new Object(),GetInstance : function( name ){return this.Instances[ name ];},_FormSubmit : function(){for ( var name in FCKeditorAPI.Instances ){var oEditor = FCKeditorAPI.Instances[ name ] ;if ( oEditor.GetParentForm && oEditor.GetParentForm() == this )oEditor.UpdateLinkedField() ;}this._FCKOriginalSubmit() ;},_FunctionQueue    : {Functions : new Array(),IsRunning : false,Add : function( f ){this.Functions.push( f );if ( !this.IsRunning )this.StartNext();},StartNext : function(){var aQueue = this.Functions ;if ( aQueue.length > 0 ){this.IsRunning = true;aQueue[0].call();}else this.IsRunning = false;},Remove : function( f ){var aQueue = this.Functions;var i = 0, fFunc;while( (fFunc = aQueue[ i ]) ){if ( fFunc == f )aQueue.splice( i,1 );i++ ;}this.StartNext();}}}';
          if (A.execScript) A.execScript(B, 'JavaScript');
          else
          {
             if (FCKBrowserInfo.IsGecko10)
             {
                eval.call(A, B);
             }
             else if(FCKBrowserInfo.IsAIR)
             {
                FCKAdobeAIR.FCKeditorAPI_Evaluate(A, B);
             }
             else if (FCKBrowserInfo.IsSafari || FCKBrowserInfo.IsGecko19)
             {
                var C = A.document;
                var D = C.createElement('script');
                D.appendChild(C.createTextNode(B));
                C.documentElement.appendChild(D);
                
             }
             else A.eval(B);
          }
          ;
          FCKeditorAPI = A.FCKeditorAPI;
          FCKeditorAPI.__Instances = FCKeditorAPI.Instances;
       }
       ;
       FCKeditorAPI.Instances[FCK.Name] = FCK;
    }
      

  25.   


    问题还没有解决呀!!?
    楼主在父窗口的 onload 事件中调用一下这个InitializeAPI函数试试.
    调用的时候判断一下iframe的readyState.
      

  26.   

    var scriptObj = C.documentElement.appendChild(D);
    scriptObj.onreadystatechange = function(){
        var state = scriptObj.readyState;
        if (state == "loaded" || state == "complete") {
            // 加载完毕
        }
    };
      

  27.   

    如果楼主还是没解决问题的话,不妨看下我自己写的在线编辑器里边的一个开头部分,到目前为止我的编辑器在IE和FF任何版本里都没问题。你上边碰到过我也碰到过类似的问题,费了好多劲才弄好的。主要是用了function里边再调用window.onload,具体我不清楚为什么可以成功的原因,我只知道得出了我要的结果。如果有兴趣你可以看下或许能解决你碰到的问题.var EditIDE,EditIDD,EditIDP;
    var ParentFormIst,ParentFormName,ParentFormItem;//是否能获取到父框架/父框架表单名/父框架表单项目
    var FormCnt,UrlHeight,AvaiHeight,NowMode=0;//NowMode:1设计 2代码 3拆分 4预览
    var View_1,View_2,View_3,View_4,View_5;
    var MSIE=window.attachEvent?true:false;
    //
    document.oncontextmenu=function(evt){return false;}
    function MyPE_Initializtion(v1,v2,v3,h,ist,formname,formitem){//初始化
    if(MSIE){
    EditIDE=window.frames[v1];EditIDE.document.designMode="on";EditIDE.document.oncontextmenu=function(evt){return false;}
    EditIDD=window.frames[v2];EditIDD.document.designMode="on";EditIDD.document.oncontextmenu=function(evt){return false;}
    EditIDP=window.frames[v3];
    }
    else{
    EditIDE=document.getElementById(v1);EditIDE.contentDocument.designMode="on";
    EditIDD=document.getElementById(v2);EditIDD.contentDocument.designMode="on";
    EditIDP=document.getElementById(v3);
    }
    window.onload=function(evt){
    ParentFormName=window.parent.document.forms[formname];
    if(typeof(ParentFormName)=="object"){ParentFormIst=true;ParentFormItem=ParentFormName.elements[formitem];}
    else{ParentFormIst=false;alert("提示:编辑器无法取得内容,建议您联系管理员!");return false;}

    if(MSIE){}//EditIDE.attachEvent("onblur",MyPE_OnBlur1);EditIDD.attachEvent("onblur",MyPE_OnBlur2);
    else{EditIDE.contentWindow.addEventListener("blur",MyPE_OnBlur1,false);EditIDD.contentWindow.addEventListener("blur",MyPE_OnBlur2,false);}

    MyPE_IniTableMenu(1);MyPE_IniTableMenu(2);MyPE_IniTableMenu(3);
    FormCnt=document.mypeform.cnt;
    UrlHeight=h;
    View_1=document.getElementById("div1");View_1.style.display="";
    View_2=document.getElementById("div2");View_2.style.display="";
    AvaiHeight=UrlHeight-View_1.offsetHeight-View_2.offsetHeight-4;//未知原因-4才正好布局满
    View_3=document.getElementById("div3");
    View_4=document.getElementById("div4");
    View_5=document.getElementById("div5");
    MyPE_SetMode(1);
    if(ist==1){
    var str=ParentFormItem.value;
    FormCnt.value=str;
    if(MSIE){EditIDD.document.body.innerHTML=str;}
    else{EditIDD.contentDocument.body.innerHTML=str;}
    }
    }
    }
      

  28.   

    我 也遇到过类似的问题,你为什么要执行 InitializeAPI()啊?这个好像是fck自己会执行的,fck是嵌在一个
    iframe中的,后来我的解决方案是
    var obj;
    if(FCKeditorAPI)
       obj=FCKeditorAPI.GetInstance("<%= this.FCKeditor1.ClientID %>");
    else
       obj=document.getElementById("<%= this.FCKeditor1.ClientID %>");
    我猜是页面初始化的时候,FCKeditorAPI还没有初始化,所以会报这错.你前面加个alert(),就相当于暂停了一下,但是此时iframe中的函数继续执行,所以就能取到.不加就不能取到.
      

  29.   

    我 也遇到过类似的问题,你为什么要执行 InitializeAPI()啊?这个好像是fck自己会执行的,fck是嵌在一个
    iframe中的,后来我的解决方案是
    var obj;
    if(FCKeditorAPI)
       obj=FCKeditorAPI.GetInstance("<%= this.FCKeditor1.ClientID %>");
    else
       obj=document.getElementById("<%= this.FCKeditor1.ClientID %>");
    我猜是页面初始化的时候,FCKeditorAPI还没有初始化,所以会报这错.你前面加个alert(),就相当于暂停了一下,但是此时iframe中的函数继续执行,所以就能取到.不加就不能取到.
      

  30.   


    改了没用啊死循环了!
    程序结构如下!
    xxx.html引用1.js,我在1.js中显示FCK编辑器
    1.js调用,2.js的viewFCK方法.该方法会调用oFCKeditor.Create() ;
    这个方法是FCK初始化的方法!这个方法会去fckeditor.html执行
    window.onload = function()
    {
      .....
    InitializeAPI() ;
      .......
    }
    我就是InitializeAPI这个方法过不去!
    总是提示我FCKeditorAPI is undefined 
    ff2.16以下和ie6,7都没问题只有ff3有这个问题!
    但是如果把1.js增加一个alert修改成下面的就没问题了不知道为什么啊
    document.write("<td>");
    alert("");
    viewFCK("......");
    document.write("<td>");
    一.1.js
    document.write("<td>");
    viewFCK("......");
    document.write("<td>");

    二.2.js
    function viewFCK(){
    ..................
    oFCKeditor.Create() ;
    }
    三.fckeditor.html
    window.onload = function()
    {
      .....
    InitializeAPI() ;
      .......
    }
    四.fckeditorcode_gecko.js
    function InitializeAPI() 

      var A = window.parent; 
    if(!A.FCKeditorAPI){ 
    return window.setTimeout(function(){InitializeAPI();},100); 

      if ( ! (FCKeditorAPI = A.FCKeditorAPI)) 
      { 
          var B = 'window.FCKeditorAPI = {Version : "2.6.2",VersionBuild : "19417",Instances : new Object(),GetInstance : function( name ){return this.Instances[ name ];},_FormSubmit : function(){for ( var name in FCKeditorAPI.Instances ){var oEditor = FCKeditorAPI.Instances[ name ] ;if ( oEditor.GetParentForm && oEditor.GetParentForm() == this )oEditor.UpdateLinkedField() ;}this._FCKOriginalSubmit() ;},_FunctionQueue    : {Functions : new Array(),IsRunning : false,Add : function( f ){this.Functions.push( f );if ( !this.IsRunning )this.StartNext();},StartNext : function(){var aQueue = this.Functions ;if ( aQueue.length > 0 ){this.IsRunning = true;aQueue[0].call();}else this.IsRunning = false;},Remove : function( f ){var aQueue = this.Functions;var i = 0, fFunc;while( (fFunc = aQueue[ i ]) ){if ( fFunc == f )aQueue.splice( i,1 );i++ ;}this.StartNext();}}}'; 
          if (A.execScript) A.execScript(B, 'JavaScript'); 
          else 
          { 
            if (FCKBrowserInfo.IsGecko10) 
            { 
                eval.call(A, B); 
            } 
            else if(FCKBrowserInfo.IsAIR) 
            { 
                FCKAdobeAIR.FCKeditorAPI_Evaluate(A, B); 
            } 
            else if (FCKBrowserInfo.IsSafari || FCKBrowserInfo.IsGecko19) 
            { 
                var C = A.document; 
                var D = C.createElement('script'); 
                D.appendChild(C.createTextNode(B)); 
                C.documentElement.appendChild(D); 
                
            } 
            else A.eval(B); 
          } 
          ; 
          FCKeditorAPI = A.FCKeditorAPI; 
          FCKeditorAPI.__Instances = FCKeditorAPI.Instances; 
      } 
      ; 
      FCKeditorAPI.Instances[FCK.Name] = FCK; 
      

  31.   

    我重新总结了一下啊.................................................问题如下程序结构如下!
    xxx.html引用1.js,我在1.js中显示FCK编辑器
    1.js调用,2.js的viewFCK方法.该方法会调用oFCKeditor.Create() ;
    这个方法是FCK初始化的方法!这个方法会去fckeditor.html执行
    window.onload = function()
    {
      .....
    InitializeAPI() ;
      .......
    }
    我就是InitializeAPI这个方法过不去!
    总是提示我FCKeditorAPI is undefined 
    ff2.16以下和ie6,7都没问题只有ff3有这个问题!
    但是如果把1.js增加一个alert修改成下面的就没问题了不知道为什么啊
    document.write("<td>");
    alert("");
    viewFCK("......");
    document.write("<td>");
    一.1.js
    document.write("<td>");
    viewFCK("......");
    document.write("<td>");

    二.2.js
    function viewFCK(){
    ..................
    oFCKeditor.Create() ;
    }
    三.fckeditor.html
    window.onload = function()
    {
      .....
    InitializeAPI() ;
      .......
    }
    四.fckeditorcode_gecko.js
    function InitializeAPI() 

      var A = window.parent; 
    if(!A.FCKeditorAPI){ 
    return window.setTimeout(function(){InitializeAPI();},100); 

      if ( ! (FCKeditorAPI = A.FCKeditorAPI)) 
      { 
          var B = 'window.FCKeditorAPI = {Version : "2.6.2",VersionBuild : "19417",Instances : new Object(),GetInstance : function( name ){return this.Instances[ name ];},_FormSubmit : function(){for ( var name in FCKeditorAPI.Instances ){var oEditor = FCKeditorAPI.Instances[ name ] ;if ( oEditor.GetParentForm && oEditor.GetParentForm() == this )oEditor.UpdateLinkedField() ;}this._FCKOriginalSubmit() ;},_FunctionQueue    : {Functions : new Array(),IsRunning : false,Add : function( f ){this.Functions.push( f );if ( !this.IsRunning )this.StartNext();},StartNext : function(){var aQueue = this.Functions ;if ( aQueue.length > 0 ){this.IsRunning = true;aQueue[0].call();}else this.IsRunning = false;},Remove : function( f ){var aQueue = this.Functions;var i = 0, fFunc;while( (fFunc = aQueue[ i ]) ){if ( fFunc == f )aQueue.splice( i,1 );i++ ;}this.StartNext();}}}'; 
          if (A.execScript) A.execScript(B, 'JavaScript'); 
          else 
          { 
            if (FCKBrowserInfo.IsGecko10) 
            { 
                eval.call(A, B); 
            } 
            else if(FCKBrowserInfo.IsAIR) 
            { 
                FCKAdobeAIR.FCKeditorAPI_Evaluate(A, B); 
            } 
            else if (FCKBrowserInfo.IsSafari || FCKBrowserInfo.IsGecko19) 
            { 
                var C = A.document; 
                var D = C.createElement('script'); 
                D.appendChild(C.createTextNode(B)); 
                C.documentElement.appendChild(D); 
                
            } 
            else A.eval(B); 
          } 
          ; 
          FCKeditorAPI = A.FCKeditorAPI; 
          FCKeditorAPI.__Instances = FCKeditorAPI.Instances; 
      } 
      ; 
      FCKeditorAPI.Instances[FCK.Name] = FCK; 
      

  32.   

     alert("5");
     InitializeAPI() ;    
     alert("6");
    换成:
    src="http://www.csdn.net/ui/scripts/Csdn/counter.js
    InitializeAPI() ;
    src="http://www.csdn.net/ui/scripts/Csdn/counter.js