问题
Basically,I have loaded tinyMCE on the textarea. And my motive is :
When the button is clicked, the editor should be filled by the description stored in database through ajax call.
It works properly in Chrome.
But when I run the script in Firefox,it works fine for the first time. But on pressing the button again, the description flashes for a second and disappears. The code works fine on refreshing the page .
What could be problem? Any help would be helpful.
回答1:
There are several possibilities.
One can be that you need to shut down the tinymce editor instance before reinitializing it a second time.
To shut down an edtor instance use:
tinymce.execCommand('mceRemoveControl',true,'editor_id');
To reinitialize use
tinymce.execCommand('mceAddControl',true,'editor_id');
回答2:
tinymce.init({
mode : "exact",
selector: 'your_textarea_selector',
theme: "modern",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste"
],
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
toolbar_items_size: 'small',
image_advtab: true,
init_instance_callback : function(editor) {
var currentEditor = editor.editorContainer;
$(currentEditor).show();
}
});
if (tinymce.editors.length>0) {
tinymce.execCommand('mceFocus', true, txt_area_id);
tinymce.execCommand('mceRemoveEditor',true, txt_area_id);
tinymce.execCommand('mceAddEditor',true, txt_area_id);
}
This works fine for me even with ajax requests. I'm using Tinymce 4.x in my JSP.
回答3:
This thing works for me:
You need to call the tinyMCE script from the very page which is containing the editor.
I am using MVC4 Razor framework. By injecting this code on my page helped me:
<script src="@Url.Content("~/scripts/tinymce/tinymce.min.js")" type="text/javascript"></script>
来源:https://stackoverflow.com/questions/11331945/tinymce-not-able-to-load-content-when-called-for-second-time-in-one-page-in-mozi