I've the below codes to create an iFrame inside a div and then append contents inside of the iFrame's body. This works fine in Chrome and Edge. But Firefox removing the appended contents right away after.
var $iframe = $('<iframe/>', {
'class' : 'editor-iframe',
'src' : '',
'border': 0,
'height' : '100%',
'width' : '100%'
});
var $iframe_editor = $('<div/>', {
'class': "editor" ,
'contenteditable' : true
});
var contents = $('#editor').html();
$iframe_editor.append(contents);
$('#editor').html($iframe);
$('#editor').find('iframe').contents().find('body').append($iframe_editor);
.editor{
border: 2px solid green;
height: 300px;
width: 300px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="editor" id="editor">
<h4>Qui ita affectus, beatum esse numquam probabis;</h4>
<p>Quacumque enim ingredimur, in aliqua historia vestigium ponimus. Commoda autem et incommoda in eo genere sunt, quae praeposita et reiecta diximus; Ille enim occurrentia nescio quae comminiscebatur; Sit hoc ultimum bonorum, quod nunc a me defenditur; </p>
</div>
You can also see the codes in this JSFiddle - https://jsfiddle.net/thb2mz3k/6/
How can i fix this? Thank you