2017-07-31 66 views
0

是否有任何方法可以将本地html页面加载到ckeditor?在ckeditor中加载html页面

<div class="text-area"> 
    <textarea cols="120" rows="10" id="editor" name="text"></textarea> 
</div> 

这是脚本:

@section Scripts { 
<script type="text/javascript"> 

    CKEDITOR.replace('editor', { 
     fullPage: true, 
     allowedContent: true  

    }); 

    CKEDITOR.instances['editor'].setData('test.html'); 

</script> 
} 
+0

你能请让我知道,如果提供的解决方案行之有效,好吗? – iXCray

+0

是的,先生。它的工作,但我改变了编辑有几个原因。无论如何,谢谢你的帮助。 –

回答

1

您需要使用不便加载这个页面,然后才填入你有数据CKEditor的。

注意,即.setData()是异步函数,所以不要立即做任何数据修改,直到您将得到确认编辑器中的数据已被正确更改。

的Javascript:

var xhr = new XMLHttpRequest(); 
xhr.open('GET', 'test.html', true); 

xhr.onload = function() { 
    if (this.status == 200) { 
    CKEDITOR.instances['editor'].setData(this.response); 
    } else { 
    // process error status here 
    } 
}; 

xhr.onerror = function() { 
    // process error status here 
}; 

xhr.send(); 

的Javascript + jQuery的

$.get('test.html') 
    .done(response=>{CKEDITOR.instances['editor'].setData(response);}) 
    .fail(/** process error here **/); 

的JavaScript +取

并非所有的浏览器都支持这一点。

填充工具是在这里:https://github.com/github/fetch

支持表是在这里:https://caniuse.com/#search=fetch

fetch('test.html') 
    .then(response=>{CKEDITOR.instances['editor'].setData(response.text);}) 
    .catch(/** process error here **/);