Concerns Regarding Inline and External JS Handling in GrapesJS Custom code #6703
Unanswered
pankaj77official-git
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I am working on a custom preview system for a project built using GrapesJS. I am attempting to handle both inline and external JavaScript within the editor, and I've created a method to preview the content as follows:
`open(editor: Editor) {
if (!editor) return;
const pages = editor.Pages.getAll().map((p: any) => {
const main = p.getMainComponent();
let html = main.toHTML({ withoutScripts: false });
const temp = document.createElement('div');
temp.innerHTML = html;
});
// Open preview window
const previewWindow = window.open('');
if (!previewWindow) return;
previewWindow.document.open();
previewWindow.document.write(`
<title>Preview</title>
<style>
body { margin: 0; }
</style>
<script>
const pages = ${JSON.stringify(pages)};
let currentBodyClasses = [];
let currentScripts = [];
let currentExternalScripts = [];
`);
previewWindow.document.close();
}
`
Question:
I have created a system to preview pages with inline and external scripts separately, but I am concerned about potential issues with this approach, especially regarding security, performance, or compatibility with GrapesJS updates.
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions