用htc實現html編輯器

HTC,全稱爲HTML Component,提供了在網頁中用腳本進行組件開發的機制。下面的代碼,在頁面中嵌入一個html編輯器,只需要幾行代碼,只因爲使用了一個預先定義好的html編輯組件。html編輯組件定義在文件"htmleditor.htc"中,使用的是javascript腳本。這個組件來自於一個免費軟件:書包行CuteIE(一款用瀏覽器形式實現的多功能、可無限擴充的個人信息助理軟件),如果程序安裝在D盤的話,那麼這個組件文件的路徑是D:/Program Files/CuteIE/System/inc/cuteie_client/1_0/htmleditor.htc。

如果要將此組件使用在自己的網站中,只需要將組件文件htmleditor.htc和圖片目錄images放置到自己的網站目錄下,然後修改下面代碼中的相關路徑指向(如IMPLEMENTATION、SystemImagesPath)即可。

<?XML:NAMESPACE PREFIX=HENS />
<?IMPORT NAMESPACE=HENS IMPLEMENTATION="/inc/cuteie_client/1_0/htmleditor.htc"/>

<hens:htmleditor id="htmleditor1" SystemImagesPath="/inc/cuteie_client/1_0/images/" width=100% height=400></hens:htmleditor>

<script language=javascript>
//提取html編輯器的內容,只需要以下代碼即可。
var oContent=htmleditor1.content;
</script>

相關資源:
書包行CuteIE下載地址:http://www.cuteie.com/CuteIESetup.exe
官方網站:http://www.cuteie.com/

由於htmleditor.htc代碼比較長,下面僅摘錄組件的屬性、事件定義部分。

<public:component tagname=htmleditor literalcontent=true>
<public:attach event=oncontentready onevent="oncontentready()" />
<public:property name="systemImagesPath" id="_hepropSystemImagesPath" GET="getSystemImagesPath" PUT="setSystemImagesPath"/>
<public:property name="content" id="_hepropContent" GET="getContent" PUT="setContent"/>
<public:property name="contentType" id="_hepropContentType" GET="getContentType" PUT="setContentType"/>
<public:event name="onblur" id="_heevtBlur"/>
</public:component>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章