2011-11-30 88 views
1

contentEditable仍然有許多瀏覽器不兼容的問題,但我想我會給它一個鏡頭,並且在我正在開發的Web應用程序中使用它。在使用它時,我發現了一堆可以通過execCommand調用的選項。 CONTENTEDITABLE爲Firefox允許您撥打有沒有辦法在webKit的contentEditable div中增加字體大小?

document.execCommand("increasefontsize",bool,value); 

document.execCommand("decreasefontsize",bool,value); 

由一個點來改變字體大小。大多數其他主流瀏覽器,特別是WebKit不支持這一點,相反你必須設置一個特定的字體大小。有沒有辦法繞過這個/ hack在WebKit中增加字體大小的工作?或者有什麼方法可以選擇,獲得當前文本的大小?

任何幫助,將不勝感激。

+0

好奇 - 這些命令的輸出html是什麼?它只是改變內聯風格? – MorganTiley

+0

也可以使用rangy如果你還沒有:) http://rangy.googlecode.com/ – MorganTiley

+0

@MorganTiley這是一個非標準的命令,將選擇包裝在''或''中(或者移除相反的標籤作爲適當的)。 – Neil

回答

2

jwysiwyg似乎使用下面的代碼:

if ($.browser.mozilla || $.browser.opera) { 
    this.editorDoc.execCommand('increaseFontSize', false, null); 
} else if ($.browser.safari) { 
    var newNode = this.editorDoc.createElement('big'); 
    this.getInternalRange().surroundContents(newNode); 
} else { 
    console.error("Internet Explorer?"); 
} 

jHtmlArea似乎使用下面的代碼:

if ($.browser.msie) { 
    this.ec("fontSize", false, this.qc("fontSize") + 1) 
} else if ($.browser.safari) { 
    this.getRange().surroundContents($(this.iframe[0].contentWindow.document.createElement("span")).css("font-size", "larger")[0]) 
} else { 
    this.ec("increaseFontSize", false, "big") 
} 

對不起,但我找不到任何上述的最終環節。

相關問題