var editor = document.getElementById("iframeId");
var editorDoc = editor.contentWindow.document;
editorDoc.designMode = "on";
editorDoc.open();
editorDoc.write("<html><head></head><body style='margin:0;padding:0'></body></html>");
editorDoc.close();
document.execCommand 功能受限 (字體大小僅 1-7、焦點切換易遺失選取區)。改用選取區 HTML 替換法:
document.selection.createRange(),Firefox/Chrome 用 window.getSelection().getRangeAt(0)。<span style="..."> 等)。range.pasteHTML,Firefox/Chrome 用 range.deleteContents() + range.insertNode()。此法支援像素級字體大小、任意 CSS 樣式,且不受焦點切換影響。