Issue #2012πŸ’¬ AnsweredOpened May 13, 2019by webdeveloper04290 reactions

How to add script for all widgets(like protectedCss)

Quick answerby artf

You can initialize custom js in the canvas in this way:

Read full answer below ↓

Question

I want to add some functions for all components accessible. when initialize editor, there is a option like protectedCss. Isn't there a way javascript like above?

Answers (3)

artfβ€’ May 19, 2019

You can initialize custom js in the canvas in this way:

const editor = grapesjs.init({
  ...
  canvas: {
    scripts: ['https://.../script.js']
  }
});

webdeveloper0429β€’ May 20, 2019

Thank you. Btw what I want to need is inline javascirpt. not external link... regards.

artfβ€’ May 27, 2019

In that case, I suggest you access the document of the iframe and to append manually the inline script (to get the document use editor.Canvas.getDocument())

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 β†’

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.