[英]Load html page inside ckeditor
有什么办法可以将本地html页面加载到ckeditor吗?
<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>
}
您需要使用smth加载此页面,然后才用您获得的数据填充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 +提取
并非所有浏览器都支持这一功能。
Polyfill在这里: 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 **/);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.