Ajax应用中CKEDITOR多实例问题的解决

今天在修改 OPENCART 的后台时。用Ajax把商品的增添编辑页面调用来。。第一次调入时,一切正常。噩梦从第二次开始。。原来是第一次点击链接,调用内容时,已经进行了一次CKEDITOR的实例化,第二次调入时必然会与第一次的冲突。。

修改:

CKEDITOR.replace('description<?php echo $language['language_id']; ?>', {
	filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
});

 之前加上

if(CKEDITOR.instances['description<?php echo $language['language_id']; ?>']) {
	CKEDITOR.remove(CKEDITOR.instances['description<?php echo $language['language_id']; ?>']);
}
 

最后代码

<script type="text/javascript">
<?php foreach ($languages as $language) { ?>
if(CKEDITOR.instances['description<?php echo $language['language_id']; ?>']) {
	CKEDITOR.remove(CKEDITOR.instances['description<?php echo $language['language_id']; ?>']);
}
CKEDITOR.replace('description<?php echo $language['language_id']; ?>', {
	filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
});
<?php } ?>
</script>
 

 

P.S. 参考 http://www.cnblogs.com/cocowool/archive/2010/09/04/1817989.html

你可能感兴趣的:(ckeditor)