Issue #2313Opened October 7, 2019by TheComputerM4 reactions

[BUG] Scripts do not work when added dynamically added to iframe <head>

Question

I am using the latest version of grapesjs (0.15.8) and running it on Windows 10 x64 on Electron (this is not a issue with electron) and am facing a problem when I try to dynamically attach scripts to the editor iframe, I have included a link to CodePen for more on this issue. In my project I have to dynamically change scripts. Scripts only work when I add them through canvas: {scripts: ['...']} not when I $(editor.Canvas.getDocument().head).append("...");

CodePen

Please suggest fix or workaround. (love the project btw)

Answers (3)

pouyamiralayiOctober 7, 20192 reactions

Hi there! see if this can help you out:

const scriptEl = document.createElement('script');
scriptEl.src = 'https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js';
editor.Canvas.getDocument().head.appendChild(scriptEl);

cheers!

TheComputerMOctober 8, 20191 reactions

Thank you very much, the fix worked, but why does it not work with jQuery?

TheComputerMOctober 9, 20191 reactions

Ok thanks a lot.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.