문제는 iframe을 표시하고 편집 가능하게 만든 후 잠시 기다려야 할 수도 있다는 것입니다. 이것은 작동하는 것 같습니다.
데모 : http://jsfiddle.net/Q6Jp9/35/
암호:
function iframe_load() {
var txtBox = $("#txtMarkup");
var iframe = document.getElementById('iframe');
var contentWindow = iframe.contentWindow ? iframe.contentWindow : iframe.contentDocument.defaultView;
$(iframe).show();
$("#btnVisual").removeClass("notSelected").addClass("selected");
$("#btnMarkup").removeClass("selected").addClass("notSelected");
contentWindow.document.designMode = 'on';
window.setTimeout(function() {
var doc = iframe.contentDocument || iframe.contentWindow.document;
if (doc.body.createTextRange) {
var range = doc.body.createTextRange();
range.pasteHTML(txtBox.val());
range.collapse(false);
range.select();
contentWindow.focus();
} else {
doc.execCommand('selectAll', null, null); //Required to prevent appending
doc.execCommand('insertHtml', false, txtBox.val());
}
contentWindow.focus();
}, 20);
return false;
}
출처
https://stackoverflow.com/questions/22019875