Javascript 在编辑器中加载html页面

Javascript 在编辑器中加载html页面,javascript,c#,html,Javascript,C#,Html,有没有办法将本地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',

有没有办法将本地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>
}
@节脚本{
CKEDITOR.replace('editor'{
整页:对,
允许内容:正确
});
CKEDITOR.instances['editor'].setData('test.html');
}

您需要使用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+fetch

并不是所有的浏览器都支持这个

Polyfill在这里:

支持表如下:


如果提供的解决方案有效,请告诉我,好吗?当然可以,先生。它起作用了,但我出于几个原因更换了编辑器。不管怎样,谢谢你的帮助。我也遇到了同样的问题,并且用你的答案解决了这个问题,只需使用“Javascript”。但是,当CKEditor加载html页面时,文本格式将消失。我应该怎么做才能保留格式?
fetch('test.html')
  .then(response=>{CKEDITOR.instances['editor'].setData(response.text);})
  .catch(/** process error here **/);