Issue #3268πŸ’¬ AnsweredOpened Feb 12, 2021by theSC0RP0 reactions

How to add javascript in the html without sanitization?

Quick answerby theSC0RP

I tried adding the script to the iframe in which the canvas renders by adding a <script> tag at the end of the body of the iframe. This works to some extent. The problem here is that when I need to update the js inside the script I will need to refresh the iframe (to remove any event listeners if present) and doing so...

Read full answer below ↓

Question

Hey @artf, I am taking javascript input from the user. I need to add this javascript inside the template HTML but it gets sanitized. Is there a way that I can turn off the sanitization? (I don't have an issue with the problems you mentioned in #3245 ) or can you add a property in the editor like allowSanitization: false If not, then how can I add the javascript to the canvas?

Answers (4)

theSC0RPβ€’ Feb 18, 2021

I tried adding the script to the iframe in which the canvas renders by adding a <script> tag at the end of the body of the iframe. This works to some extent. The problem here is that when I need to update the js inside the script I will need to refresh the iframe (to remove any event listeners if p...

artfβ€’ Feb 19, 2021

Can you provide a reproducible demo of your issue, please?

theSC0RPβ€’ Feb 23, 2021

Thanks for the reply @artf. I was doing a mistake while updating the iframe so now my problem is solved! Just another question, is there any built-in method to refresh the iframe?

GJSBlockβ€’ May 17, 2026

Thanks for reporting this, @theSC0RP. Great suggestion about How to add javascript in the html without sanitization?! While this specific feature isn't yet in the core API, there are several ways to achieve similar behavior. Using the event system: Alternative approaches: Listen to selector:add for...

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...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins β†’
Premium option

Premium plugins ship with support, regular updates, and production-ready features β€” save days of integration work.

Browse premium plugins β†’

Related tutorials

In-depth guides on the same topic.

All tutorials β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.