2010-08-19 7 views
0

저는 JavaScript에 익숙하지 않으므로 제발 참아주십시오. 나는 커스텀 WYSIWYG 편집기를 사용하고있다. (이미 작성한 것을 사용하고 싶지 않다. 그래서 제안하지 말아라.)Javascript 잘못된 인수?

Internet Explorer에서 작동하는 데 문제가 있습니다. 여기

document.getElementById('editor').contentWindow.document.execCommand("styleWithCSS", false, "false"); 

는 전체 스크립트입니다 : 그것은 다음과 같은 나에게 라인에 잘못된 아규먼트의 오류를 제공

function textstyle(a) { 
    document.getElementById(a).style.visibility = 'visible'; 
    document.getElementById('editor').contentWindow.focus(); 
} 

function option(a,b) { 
    document.getElementById('editor').contentWindow.document.execCommand(a, false, b); 
    document.getElementById('editor').contentWindow.focus(); 
} 

function button(a) { 
    document.getElementById('editor').contentWindow.document.execCommand(a, false, null); 
    document.getElementById('editor').contentWindow.focus(); 
} 

var colorSelection; 

function selectColor(selection) { 
    colorSelection = selection; 
    document.getElementById('colorSelector').style.left = 0 + document.getElementById(selection).offsetLeft + "px"; 
    document.getElementById('colorSelector').style.top = 0 + document.getElementById(selection).offsetTop + document.getElementById(selection).offsetHeight + "px"; 
    document.getElementById('colorSelector').style.visibility = 'visible'; 
    return; 
} 

function changeColor(colorCode) { 
    document.getElementById('editor').contentWindow.document.execCommand(colorSelection, false, colorCode); 
    document.getElementById('colorSelector').style.visibility = 'hidden'; 
    document.getElementById('editor').contentWindow.focus(); 
    return; 
} 

function dismissmenu() 
{ 
    document.getElementById("colorSelector").style.visibility = 'hidden'; 
    document.getElementById("fontlist").style.visibility = 'hidden'; 
    document.getElementById("formatlist").style.visibility = 'hidden'; 
    document.getElementById("sizelist").style.visibility = 'hidden'; 
} 

function Start() { 
    document.getElementById('editor').contentWindow.document.designMode = "on"; 
    document.getElementById('editor').contentWindow.document.execCommand("styleWithCSS", false, "false"); 

    try { 
     document.getElementById('editor').contentWindow.document.execCommand("undo", false, null); 
     editormode = "true"; 
    } catch (e) { 
     editormode = "false"; 
    } 

    if (document.addEventListener) { 
     document.addEventListener("mouseup", dismissmenu, true); 
     document.getElementById("editor").contentWindow.document.addEventListener("mouseup", dismissmenu, true); 
     document.addEventListener("keypress", dismissmenu, true); 
     document.getElementById("editor").contentWindow.document.addEventListener("keypress", dismissmenu, true); 
    } else if (document.attachEvent) { 
     document.attachEvent("mouseup", dismissmenu, true); 
     document.getElementById("editor").contentWindow.document.attachEvent("mouseup", dismissmenu, true); 
     document.attachEvent("keypress", dismissmenu, true); 
     document.getElementById("editor").contentWindow.document.attachEvent("keypress", dismissmenu, true); 
    } 
} 

function switchEditorMode() { 
    if (editormode == "true") { 

     var replaceTagsByMode = function(html, editormode) { 
      var tags = {}; 
      for (var i=0, a=['b', 'i', 'u', 'strike', 'sub', 'sup']; i<a.length; i++) { 
       tags[['<', a[i], '>'].join('')] = ['[', a[i], ']'].join(''); 
       tags[['</', a[i], '>'].join('')] = ['[/', a[i], ']'].join(''); 
      } 
      for (var html_tag in tags) { 
       if (tags.hasOwnProperty(html_tag)) { 
        html = html.replace.apply(
        html, editormode ? [html_tag, tags[html_tag], 'g'] : [tags[html_tag], html_tag, 'g']); 
       } 
      } 
      return html; 
     }; 

     var editor_body = document.getElementById('editor').contentWindow.document.body; 
     editor_body.innerHTML = replaceTagsByMode(editor_body.innerHTML, editormode); 


     editormode = "false"; 

    } else { 

     var replaceTagsByMode = function(html, editormode) { 
      var tags = {}; 
      for (var i=0, a=['b', 'i', 'u', 'strike', 'sub', 'sup']; i<a.length; i++) { 
       tags[['[', a[i], ']'].join('')] = ['<', a[i], '>'].join(''); 
       tags[['[/', a[i], ']'].join('')] = ['</', a[i], '>'].join(''); 
      } 
      for (var html_tag in tags) { 
       if (tags.hasOwnProperty(html_tag)) { 
        html = html.replace.apply(
        html, editormode ? [html_tag, tags[html_tag], 'g'] : [tags[html_tag], html_tag, 'g']); 
       } 
      } 
      return html; 
     }; 

     var editor_body = document.getElementById('editor').contentWindow.document.body; 
     editor_body.innerHTML = replaceTagsByMode(editor_body.innerHTML, editormode); 


     editormode = "true"; 

    } 
} 
+0

'나와 함께있어주세요. '미안하지만 아직 그 단계에 대한 준비가되어 있다고 생각하지 않습니다. – Pointy

답변

2

MSDN의 문서에서, StyleWithCSS이 존재하는 command identifier하지 않은 것 같습니다 .

+0

알겠습니다. 이 가이드에 대한 정보가 있습니다. https://developer.mozilla.org/en/Rich-Text_Editing_in_Mozilla 브라우저가 HTML – Cory

+0

인 스타일보다 브라우저가 FF인지 감지해야 할 수 있습니다. @Cory : FF를 감지하지 마십시오. 대신 "기능 감지"사용 http://www.jibbering.com/faq/notes/detect-browser/ – dolmen

+0

Oded가 정확합니다. "StyleWithCSS"는 Mozilla에 의해 도입되었으며 IE에 구현되지 않았습니다. 'try ... catch' 명령으로 호출을 둘러 쌈으로써 쉽게 감지 할 수 있습니다. –

관련 문제