动态加载js时无法启动微小的mce [英] tiny mce can't be inited when load js dynamically
问题描述
我在tinyMCE上遇到了麻烦,当我将<script type="text/javascript" src="/scripts/tiny_mce/tiny_mce.js">
放入<head>
并将init代码放在<textarea class="tinyMceEditor">
之前时,它工作正常.
初始化代码是这样的:
i am having trouble with tinyMCE, when i put <script type="text/javascript" src="/scripts/tiny_mce/tiny_mce.js">
to <head>
, and put init code before the <textarea class="tinyMceEditor">
, it works fine.
the init code is like this:
tinyMCE.init({
mode : "specific_textareas",
editor_selector : "tinyMceEditor",
plugins : "inlinepopups,advlink",
convert_urls : false,
theme : "advanced",
theme_advanced_buttons1 : "link,unlink",
width: "602",
height: "175",
theme_advanced_statusbar_location : "none"});
但是现在,我想推迟tiny_mce.js的加载,当用户第一次单击按钮时,tiny_mce.js将被加载,然后将<textarea class="tinyMceEditor">
附加到<body>
,然后执行init与先前的代码一起工作,但是这次,它不会初始化tinyMCE编辑器,它仅显示<textarea class="tinyMceEditor">
But now, i want to defer the loading of tiny_mce.js, when user click a button on the first time, the tiny_mce.js will be loaded, and then append the <textarea class="tinyMceEditor">
to <body>
, then do the init work with the previous code, but this time, it won't init the tinyMCE editor, it only shows the <textarea class="tinyMceEditor">
用谷歌搜索,但是没有找到与此相关的任何东西,有人遇到过这个问题吗?
googled, but find nothing related to this, anyone has met this problem?
任何建议将不胜感激.
我研究了chrome网站开发人员工具,发现如果我动态加载tinymce.js,则不会加载所需的其他js,例如en.js,editer_template.js,editor_plugin.js等.即使我将这些js文件添加到动态加载中,tinymce也仍然无法启动.
i looked into chrome web developer tools and found that if i dynamically load the tinymce.js, other js needed like en.js, editor_template.js, editor_plugin.js etc won't be loaded. even when i add these js files to dynamically loading, the tinymce still can't be inited.
谢谢您的帮助,我看着萤火虫,在将<textarea
附加到<body>
之前,我确实加载了tinymce.js,然后附加了<textarea>
,并做了tinymce init()
,我正在使用LazyLoad(jQuery插件)动态加载js文件.
thank you for your help, i watched in firebug, and i do get the tinymce.js loaded before append <textarea
to <body>
, then i append the <textarea>
, and do the tinymce init()
, i am using LazyLoad(jQuery plugin) to dynamically load the js files.
这是我所做的
if(typeof TinyMCE == "undefined"){
//dynamically load the tinymce.js
LazyLoad(['tinymce.js'],function(){
//callback function, called after tinymce is loaded
$('body').append('<textarea class="TinyMceEditor"/>');
tinyMCE.init({init settings});
});
}
如果我不动态加载tinymce.js,只需在<head>
中放置一个<script>
标记,即可启动tinyMCE,但是当我动态加载tinymce.js时,它将不起作用.有这个想法吗?
if i don't load tinymce.js dynamically, just put a <script>
tag in <head>
, the tinyMCE can be inited , but when i load tinymce.js dynamically, it doesn't work. Any idea with this?
推荐答案
经过一天的工作,终于找到了解决方法,只需放上
after a day's work, finally found the solution, just put
window.tinymce.dom.Event.domLoaded = true;
之前
tinymce.init();
然后可以正确初始化tinymce.
then the tinymce can be inited correctly.
这篇关于动态加载js时无法启动微小的mce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!