2016-06-22 12 views
0

iframeとtextareaを使用してリアルタイムのHTMLエディタを作成しようとしていますが、何らかの理由で私のコードがエクスパンションされません。iFrameを使用したリアルタイムHtml Edtior(私が間違っていること)

誰かが自分のコードに何が間違っているのか教えていただけますか?

<script type="text/javascript"> 
var old = ''; 

function update(){ 
    var textarea = document.getElementById('code'); 
    var iFrame = document.getElementById('output').contentWindow.document; 

    if (old != textarea.value){ 
    old = textarea.value; 
    iFrame.clear(); 
    iFrame.write(old); 
    } 

    window.setTimeout(update, 150); 
} 

HTML

<body onload="update()"> 

    <textarea id="code"></textarea> 

    <iframe id="output"></iframe> 
    </body> 

答えて

0

は、これはあなたがここに

var old = ''; 
 
function update(){ 
 
    var textarea = document.getElementById('code'); 
 
    var iFrame = document.getElementById('output'); 
 
    var IframeDocument=document.getElementById('output').contentDocument 
 
    if (old != textarea.value){ 
 
    old = textarea.value; 
 
    iFrame.src="about:blank"; 
 
    IframeDocument.write(old); 
 
    } 
 

 
    window.setTimeout(update, 150); 
 
} 
 
window.onload=update();
<body > 
 
    <textarea id="code"></textarea> 
 
    <iframe id="output"></iframe> 
 
</body> 
 
    
 

必要とするものであるFiddleDemo

+0

をいただきありがとうございますですあなたの返信はそれは私のために働いていませんでした。 – Abdulrhman

+0

Uは、フィドルのデモを試みましたか?そして、それがあなたのために仕事をしなかったなら、何か特殊な事件や特別な条件を忘れてしまったことがあります。 – Manish

+0

私はフィドルのデモを試みました。問題はiframeが文字の入力後に一度更新されていたことです – Abdulrhman

関連する問題