Topic: Dynamically load tiny_mce.js after window.load
I'm having some trouble dynamically loading the tiny_mce.js file that's normally included via a script tag on the page that you want a TinyMCE editor.
I want to include this file dynamically, *after* the page has loaded. It seems that if this file is loaded after the window.load event has passed, TinyMCE can't work correctly: render() doesn't execute because Event.domLoaded is false (because _pageInit hasn't been called) but the document 'init' event will never happen because the tiny_mce.js source was loaded after the page was loaded.
I have included a small example that shows what I want to do.
<html>
<head>
<script id="tinymce" type="text/javascript"></script>
<script type="text/javascript">
function loadTinyMce() {
document.getElementById('tinymce').src = '<path>/tiny_mce/tiny_mce_src.js';
}
function setup() {
tinyMCE.init({
mode : "none",
});
var ed = new tinymce.Editor('content', {
theme : "advanced",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
});
ed.render();
}
</script>
</head>
<body>
<textarea id="content" style="width:100%"></textarea>
<a href="javascript:loadTinyMce();">Load TinyMCE</a><br />
<a href="javascript:setup();">Setup TinyMCE</a><br />
</body>
</html>In the above example HTML page, I want to be able to click the first link to load TinyMCE after the page has finished loading, and then click the second link to actually start using TinyMCE on the page. You can see that if you click the second link first, you get an error. If you attempt to load TinyMCE first by clicking the first link, you don't get any errors when clicking the second link, but nothing happens because TinyMCE hasn't been properly initialized.