1

ご覧のとおり、以下に、テキストを太字にするための関数doRichEditCommand()SetToBold()を 2 つ示します。

私の目標は、最初に、すべての主要なブラウザーで問題なく動作するため、に埋め込まれたテキストエリアでdoRichEditCommand()を動作させることです。次に、 SetToBold()のようなexecCommand関数を動作させることです。 - iframeの場合の browser 。iframe

最初の関数を機能させるために、designModeを有効にしました。ただし、有効にすると、テキストエリアは編集できなくなります。

textarea以下のコードを変更して、関数が埋め込まれた内で機能するようにするにはどうすればよいiframeですか?

よろしくお願いします。

<html>
<head>
<script type="text/javascript">

function getIFrameDocument(aID){
// if contentDocument exists, W3C compliant (Mozilla)
if (document.getElementById(aID).contentDocument){
return document.getElementById(aID).contentDocument;
} else {
// IE
return document.frames[aID].document;
 }
}

function load(){
getIFrameDocument("editorWindow").designMode = "On";
}

function doRichEditCommand(aName, aArg){
getIFrameDocument('editorWindow').execCommand(aName,false, aArg);
document.getElementById('editorWindow').contentWindow.focus()
} 

function SetToBold () {
        document.execCommand ('bold', false, null);
    }
</script>
</head>
<body onload="load()">
  <iframe id="editorWindow" src="you.php"></iframe>
  <button onclick="doRichEditCommand('bold')" style="font-weight:bold;">B</button>
  <button onclick="SetToBold();">Bold</button>
</body>
</html>

PS "you.php" は含まれていません。必要なタグとテキストエリアだけだからです。

4

0 に答える 0