Hi, I'm new here, please forgive me if I've missed something obvious.
The simple HTML file below implements 2 input areas on the same page. The JavaScript at the top simply wants to display the contents of the second input area. When the file is accessed locally (eg. c:\wwwroot\test.html) this works fine, in both Firefox and IE.
However when I access it via localhost (eg. http://localhost/test.html), IE performs ok, but Firefox (mine is 2.0.0.18) gives me a JavaScript error: oFCKeditor has no properties, Line 18. That is, GetInstance('fckfield2') is failing to find the second instance of the editor. Getting "fckfield1" works 100% of the time. Getting "fckfield2" fails only when file is accessed via http using Firefox.
I can't for the life of me work out what is causing this. Can someone please try it out and advise?
Reproduce error (hopefully) by accessing the file a) via HTTP, and b) using Firefox.
Code follows:
<html> <head> <title></title> <script type="text/javascript" src="js/fckeditor/fckeditor.js"></script> <script> var oFCKeditor function doSomething() { oFCKeditor = FCKeditorAPI.GetInstance('fckfield2') alert(oFCKeditor.GetXHTML(false)) } </script> </head> <body> <form name="form1" method="post" action="dosomething.php"> <div> <script type="text/javascript"> oFCKeditor = new FCKeditor('fckfield1') oFCKeditor.BasePath = 'js/fckeditor/' oFCKeditor.Height = 170 oFCKeditor.Value = 'blah 1' oFCKeditor.Create() </script> </div> <div> <script type="text/javascript"> oFCKeditor = new FCKeditor('fckfield2') oFCKeditor.BasePath = 'js/fckeditor/' oFCKeditor.Height = 170 oFCKeditor.Value = 'blah 2' oFCKeditor.Create() </script> </div> <div><input type="button" value="Submit" onclick="doSomething()"/></div> </form> </body> </html>
Re: A solution for multiple FCK instances in Firefox
Ok, this seems to be a compatibility problem with Firebug 1.2.1 running.
The problem I'm experiencing is similar to this recent problem in Drupal:
http://drupal.org/node/303428#comment-994282
With Firebug enabled in Firefox, FCKeditorAPI.GetInstance( js_id ) is unable to return an object reference for anything other than the first FCKEditor object on any one page.
Re: A solution for multiple FCK instances in Firefox
My problem seemed similar to this:
http://drupal.org/node/303428#comment-1048816
So in my FCKEditor v2.6.3 file editor\js\fckeditorcode_gecko.js I changed the following on line 38:
From:
else if (FCKBrowserInfo.IsSafari)
To:
else if (FCKBrowserInfo.IsSafari || FCKBrowserInfo.IsGecko19)
I cleared the cache and reloaded the page - at first, it worked! The alert box came up with the contents of the second instance. But then I reloaded the page again, and it failed with the same JS error. Subsequent page reloads repeated the error. Clearing the cache and reloading fixes the error on the first page view only. So this seems to be a timing problem, perhaps when instantiating objects.
I've reverted the above change, so the fckeditorcode_gecko.js file is now back to it's original v2.6.3 state. Cleared the cache in FF again, and the code worked. Refreshed the page, code fails, and continues to fail until I clear the cache again, which forces all js files to be re-read and perhaps that coincidentally alleviates what may be an asynchronous timing problem in the FCK code, only manifesting in Firefox.
Re: A solution for multiple FCK instances in Firefox
The 5am workaround is here.
The problem is clearly a timing issue with asynchronous creation of the FCKeditorAPI object in Firefox. When FF and IE are asked to instantiate FCKEditor objects, FF is significantly slower. Shamefully slow I'd say, and I'm comparing it to IE6, which sets up multiple FCKEditor areas almost instantly.
In my previous posts, I was under the impression the issue was compatibility with Firebug running in Firefox. Turns out, it's only because Firebug slows things down a little, and makes this asynchronous timing issue more frequent. It still manifests in FF sometimes with Firebug disabled.
The problem with the FCK code in FF, is that the FCKeditorAPI object is not made available to the client code immediately after the first FCKEditor object is created. I tried the following code (using the "ReplaceTextarea" methodology):
Re: A solution for multiple FCKEditor instances in Firefox
Re: A solution for multiple FCKEditor instances in Firefox