<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>色胚子部落 &#187; FCKeditor</title>
	<atom:link href="http://blog.colorbase.tw/tag/fckeditor/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.colorbase.tw</link>
	<description>訊息多變的時代裡，需要多學習多思考</description>
	<lastBuildDate>Mon, 15 Aug 2011 03:29:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>解決一個頁面有兩個FCKeditor時，無法使用FCKeditorAPI.GetInstance的問題</title>
		<link>http://blog.colorbase.tw/programming/509</link>
		<comments>http://blog.colorbase.tw/programming/509#comments</comments>
		<pubDate>Thu, 18 Sep 2008 05:56:19 +0000</pubDate>
		<dc:creator>阿育</dc:creator>
				<category><![CDATA[程式設計]]></category>
		<category><![CDATA[FCKeditor]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://blog.colorbase.tw/?p=509</guid>
		<description><![CDATA[FCKeditor跟Wordpress使用的TinyMCE一樣，都是OpenSource的WYSIWYG Editor(所見即所得編輯器)，一直以來比較習慣用FCKeditor這套編輯器來幫網頁加入可以編輯HTML的功能，但今天突然發現如果一個頁面有兩個FCKeditor且在Firefox運行時，若要使用FCKeditorAPI.GetInstance()來取得編輯器的instance，只有第一個可以正確取得，第二個將會是undefined，第三個以上沒試但應該也難逃厄運了。

運行環境：

Firefox 3.0.1
FCKeditor 2.6.3

發生錯誤可能原因：

fckeditorcode_gecko.js 有Bug
Firefox有Bug或與FCKeditor有小部份衝突

解決概念：
如果是第一個原因，我實在沒興趣把壓縮過的fckeditorcode_gecko.js解回來檢查(壓縮過都還有253K啊！)，更別說Firefox有bug能幫上什麼忙了，不過幸好在FCKeditor JavaScript API有提到，可以建立一個名為FCKeditor_OnComplete的callback function，當FCKeditor載入完畢後將會呼叫這個function並傳入一個參數，這個參數就是目前裝載完畢的FCKeditor Instance，只要把這個參數記錄下來，就可以直接使用Instance，不需要用FCKeditorAPI.GetInstance()來取得，這樣一來便解決問題了。
解決方式：
在FCKeditor載入之前加入以下Javascript


//修正FckEditor錯誤
var __fckEditorInstance_  = new Array();//用來儲存FCKeditor Instance的陣列

function FCKeditor_OnComplete( editorInstance )
{
	__fckEditorInstance_[editorInstance.Name] = editorInstance;
}

function getFckInst(idname)
{
	return __fckEditorInstance_[idname];
}


之後就可以利用getFckInst()來代替FCKeditorAPI.GetInstance()取得FCKeditor Instance
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.fckeditor.net/" target="_blank">FCKeditor</a>跟Wordpress使用的<a href="http://tinymce.moxiecode.com/" target="_blank">TinyMCE</a>一樣，都是OpenSource的WYSIWYG Editor(所見即所得編輯器)，一直以來比較習慣用FCKeditor這套編輯器來幫網頁加入可以編輯HTML的功能，但今天突然發現如果一個頁面有兩個FCKeditor且在Firefox運行時，若要使用FCKeditorAPI.GetInstance()來取得編輯器的instance，只有第一個可以正確取得，第二個將會是undefined，第三個以上沒試但應該也難逃厄運了。<br />
<span id="more-509"></span><br />
<span style="color: #008080;"><strong>運行環境：</strong></span></p>
<ul>
<li>Firefox 3.0.1</li>
<li>FCKeditor 2.6.3</li>
</ul>
<p><span style="color: #008080;"><strong>發生錯誤可能原因：</strong></span></p>
<ol>
<li>fckeditorcode_gecko.js 有Bug</li>
<li>Firefox有Bug或與FCKeditor有小部份衝突</li>
</ol>
<p><span style="color: #008080;"><strong>解決概念：</strong></span></p>
<p>如果是第一個原因，我實在沒興趣把壓縮過的fckeditorcode_gecko.js解回來檢查(壓縮過都還有253K啊！)，更別說Firefox有bug能幫上什麼忙了，不過幸好在<a href="http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/JavaScript_API" target="_blank">FCKeditor JavaScript API</a>有提到，可以建立一個名為FCKeditor_OnComplete的callback function，當FCKeditor載入完畢後將會呼叫這個function並傳入一個參數，這個參數就是目前裝載完畢的FCKeditor Instance，只要把這個參數記錄下來，就可以直接使用Instance，不需要用FCKeditorAPI.GetInstance()來取得，這樣一來便解決問題了。</p>
<p><span style="color: #008080;"><strong>解決方式：</strong></span></p>
<p>在FCKeditor載入之前加入以下Javascript</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:e7260e77-5e65-4ebc-af8d-01c0054aa9ca" class="wlWriterEditableSmartContent">
<pre name="code" class="js:nogutter">
//修正FckEditor錯誤
var __fckEditorInstance_  = new Array();//用來儲存FCKeditor Instance的陣列

function FCKeditor_OnComplete( editorInstance )
{
	__fckEditorInstance_[editorInstance.Name] = editorInstance;
}

function getFckInst(idname)
{
	return __fckEditorInstance_[idname];
}
</pre>
</div>
<p>之後就可以利用getFckInst()來代替FCKeditorAPI.GetInstance()取得FCKeditor Instance</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.colorbase.tw/programming/509/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

