在弹出窗口中编辑HTML,可以通过以下步骤实现:
var popupWindow = window.open("", "popup", "width=500,height=500");
var popupWindow = window.open("", "popup", "width=500,height=500");
popupWindow.document.write('<html><head><script src="https://cdn.ckeditor.com/ckeditor5/30.0.0/classic/ckeditor.js"></script></head><body><textarea id="editor"></textarea><script>ClassicEditor.create(document.querySelector("#editor"));</script></body></html>');
popupWindow.document.write('<button onclick="saveHTML()">保存</button>');
在弹出窗口中定义保存HTML的函数:
popupWindow.saveHTML = function() {
var htmlContent = popupWindow.document.querySelector("#editor").innerHTML;
window.opener.receiveHTML(htmlContent);
popupWindow.close();
};
window.receiveHTML = function(htmlContent) {
// 处理接收到的HTML内容
console.log(htmlContent);
};
通过以上步骤,就可以在弹出窗口中编辑HTML,并将编辑后的HTML内容传递回父窗口进行处理。
注意:以上示例中使用了CKEditor作为HTML编辑器,你也可以根据自己的需求选择其他编辑器库或自行实现一个编辑器。
领取专属 10元无门槛券
手把手带您无忧上云