question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
pouyamiralayicommented, Oct 7, 2019

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!

1reaction
TheComputerMcommented, Oct 9, 2019

Ok thanks a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does appending a <script> to a dynamically created ...
One thing that seems unusual is that the the code in iframe_test.js even works; I haven't loaded jQuery in the <iframe> itself, only...
Read more >
Dynamically created iframe contents don't stay if script that ...
Yes., Calling "Start" works well. But inserting a script node with Start in it has this problem. I see that iframe that is...
Read more >
IFrame in IE9 won't run script when dynamically updated
I am trying to get the following page to run in IE9. Basically it takes a prebuilt HTML page stored as a string...
Read more >
content script load into dynamically added IFrame
Just identified, if the Iframe src is different then actual src then it's not able to load content scripts into it,. for example:...
Read more >
Resource loading: onload and onerror
For instance, there's no such script (error 404) or the server is down ... Most resources start loading when they are added to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found